movai_core_shared.core.zmq package

Submodules

movai_core_shared.core.zmq.zmq_base module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023

class movai_core_shared.core.zmq.zmq_base.ZMQBase(identity: str, addr: str)

Bases: ABC

A base class for zmq components.

abstract handle_socket_errors(exc)

An abstract method which allows every ZMQ component to handle the error by it’s own needs.

abstract init_lock()

An abstract method which allows every ZMQ component to initiliaze the lock by it’s own needs.

abstract init_socket()

An abstract medthod which allows every ZMQ component to initiliaze the socket by it’s own needs.

abstract receive(use_lock: bool = False)

An abstract method which allows every ZMQ component to receive the message by it’s own needs.

recieve(use_lock: bool = False)

Function for retrocompatibility which call recieve() member function

release_lock() None

An abstract method which allows every ZMQ component to release the lock by it’s own needs.

abstract send(msg: dict, use_lock: bool = False)

An abstract method which allows every ZMQ component to send the message by it’s own needs.

movai_core_shared.core.zmq.zmq_client module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023

class movai_core_shared.core.zmq.zmq_client.AsyncZMQClient(identity: str, addr: str)

Bases: ZMQClient

An Async implementation of ZMQ Client

init_lock() None

Initializes the lock the async way.

async receive(use_lock: bool = False) dict

Asyncronously receives data from the server.

Parameters:
  • (dict) – A response from the server.

  • use_lock (bool) – Whether to use the lock.

Returns:

A response from the server. In case of an error, an empty dict is returned.

Return type:

(dict)

async send(msg: dict, use_lock: bool = False) None

Asynchrounously send the message to the server.

Parameters:
  • msg (dict) – The message to send.

  • use_lock (bool) – Whether to use the lock.

Returns:

None

class movai_core_shared.core.zmq.zmq_client.ZMQClient(identity: str, addr: str)

Bases: ZMQBase

A very basic implementation of ZMQ Client

handle_socket_errors(exc: ZMQError, reset_socket=True) None

Handles the socket errors :param exc: the exception :type exc: zmq.error.ZMQError :param reset_socket: whether to reset the socket :type reset_socket: bool

Returns:

None

Raises:

exc – the exception

init_lock() None

Initializes the lock.

init_socket() None

Initializes the socket and connect to the server.

receive(use_lock: bool = False) dict

Synchronously receives data from the server. :param use_lock: whether to use the lock :type use_lock: bool

Returns:

A response from the server.

Return type:

(dict)

reset(force: bool = False, use_lock: bool = False) None

Resets the socket and reconnects to the server.

send(msg: dict, use_lock: bool = False) None

Synchronously sends a message to the server. :param data: the msg representation :type data: dict :param use_lock: whether to use the lock :type use_lock: bool

Returns:

None

zmq_socket_type = 5

movai_core_shared.core.zmq.zmq_helpers module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023

movai_core_shared.core.zmq.zmq_helpers.create_msg(msg: dict)

create the msg in json format.

Parameters:

msg (dict) – A dictionary format of the messge.

Returns:

json string

movai_core_shared.core.zmq.zmq_helpers.extract_reponse(buffer: List[bytes]) dict

Extracts the response from the buffer.

Parameters:

buffer – List of memory buffers containing the message.

Returns:

A response from server.

Return type:

(dict)

movai_core_shared.core.zmq.zmq_helpers.generate_zmq_identity(zmq_type: str) str

Generate a unique identity for ZMQ clients

Parameters:

zmq_type (str) – The type of zmq object.

Returns:

The unique identity.

Return type:

str

movai_core_shared.core.zmq.zmq_manager module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023

class movai_core_shared.core.zmq.zmq_manager.ZMQManager

Bases: object

This class will host ZMQ objects by their type and address.

classmethod get_client(server_addr: str, client_type: ZMQType) ZMQClient
classmethod validate_server_addr(server_addr: str)
class movai_core_shared.core.zmq.zmq_manager.ZMQType(value)

Bases: Enum

An enumeration.

ASYNC_CLIENT = 2
ASYNC_PUBLISHER = 4
ASYNC_SUBSCRIBER = 6
CLIENT = 1
PUBLISHER = 3
SUBSCRIBER = 5
class movai_core_shared.core.zmq.zmq_manager.ZMQTypeValue(*args, **kwargs)

Bases: dict

identity: str
type: Type[ZMQClient]

movai_core_shared.core.zmq.zmq_publisher module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023

class movai_core_shared.core.zmq.zmq_publisher.AsyncZMQPublisher(identity: str, addr: str)

Bases: AsyncZMQClient

An Async implementation of ZMQ Publisher with specific socket type.

zmq_socket_type = 1
class movai_core_shared.core.zmq.zmq_publisher.ZMQPublisher(identity: str, addr: str)

Bases: ZMQClient

A very basic implementation of ZMQ publisher with specific socket type.

zmq_socket_type = 1

movai_core_shared.core.zmq.zmq_server module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023

class movai_core_shared.core.zmq.zmq_server.ZMQServer(server_name: str, bind_addr: str, debug: bool = False)

Bases: ABC

This class is a base class for any ZMQ server.

async at_shutdown()

A funtion which is called once at server shutdown and can be used for initializing other tasks.

async at_startup()

A funtion which is called once at server startup and can be used for initializing other tasks.

close() None

close the zmq socket.

abstract async handle(buffer: List[bytes]) None
init_server()

Initializes the server to listen on the specified address.

async spin() None

accepts new connections requests to zmq.

start() bool

The main message dispatch loop.

Returns:

True on success, False otherwise.

Return type:

bool

stop()

Stops the server from running.

movai_core_shared.core.zmq.zmq_subscriber module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023

class movai_core_shared.core.zmq.zmq_subscriber.AsyncZMQSubscriber(identity: str, addr: str)

Bases: AsyncZMQClient

An Async implementation of ZMQ subscriber

zmq_socket_type = 2
class movai_core_shared.core.zmq.zmq_subscriber.ZMQSubscriber(identity: str, addr: str)

Bases: ZMQClient

A very basic implementation of ZMQ Subscriber

zmq_socket_type = 2

Module contents

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Usage:

Basic 0MQ client for connecting 0MQ servers.

Developers: - Erez Zomer (erez@mov.ai) - 2023