executorlib.standalone.interactive.communication.SocketInterface#

class executorlib.standalone.interactive.communication.SocketInterface(spawner=None, log_obj_size: bool = False, time_out_ms: int = 1000)[source]#

Bases: object

The SocketInterface is an abstraction layer on top of the zero message queue.

Parameters:
  • spawner (executorlib.shared.spawner.BaseSpawner) – Interface for starting the parallel process

  • log_obj_size (boolean) – Enable debug mode which reports the size of the communicated objects.

  • time_out_ms (int) – Time out for waiting for a message on socket in milliseconds.

__init__(spawner=None, log_obj_size: bool = False, time_out_ms: int = 1000)[source]#

Initialize the SocketInterface.

Parameters:
  • spawner (executorlib.shared.spawner.BaseSpawner) – Interface for starting the parallel process

  • log_obj_size (boolean) – Enable debug mode which reports the size of the communicated objects.

  • time_out_ms (int) – Time out for waiting for a message on socket in milliseconds.

Methods

__init__([spawner, log_obj_size, time_out_ms])

Initialize the SocketInterface.

bind_to_random_port()

Identify a random port typically in the range from 49152 to 65536 to bind the SocketInterface instance to.

bootup([command_lst, stop_function])

Boot up the client process to connect to the SocketInterface.

receive_dict()

Receive a dictionary from a connected client process.

send_and_receive_dict(input_dict)

Combine both the send_dict() and receive_dict() function in a single call.

send_dict(input_dict)

Send a dictionary with instructions to a connected client process.

shutdown([wait])

Shutdown the SocketInterface and the connected client process.

Attributes

status

bind_to_random_port() int[source]#

Identify a random port typically in the range from 49152 to 65536 to bind the SocketInterface instance to. Other processes can then connect to this port to receive instructions and send results.

Returns:

port the SocketInterface instance is bound to.

Return type:

int

bootup(command_lst: list[str] | None = None, stop_function: Callable | None = None)[source]#

Boot up the client process to connect to the SocketInterface.

Parameters:
  • command_lst (list) – list of strings to start the client process

  • stop_function (Callable) – Function to stop the interface.

receive_dict() dict[source]#

Receive a dictionary from a connected client process.

Returns:

dictionary with response received from the connected client

Return type:

dict

send_and_receive_dict(input_dict: dict) dict[source]#

Combine both the send_dict() and receive_dict() function in a single call.

Parameters:

input_dict (dict) – dictionary of commands to be communicated. The key “shutdown” is reserved to stop the connected client from listening.

Returns:

dictionary with response received from the connected client

Return type:

dict

send_dict(input_dict: dict)[source]#

Send a dictionary with instructions to a connected client process.

Parameters:

input_dict (dict) – dictionary of commands to be communicated. The key “shutdown” is reserved to stop the connected client from listening.

shutdown(wait: bool = True)[source]#

Shutdown the SocketInterface and the connected client process.

Parameters:

wait (bool) – Whether to wait for the client process to finish before returning. Default is True.