interaction.master.connection

_ISlaveConnection

class ding.interaction.master.connection._ISlaveConnection[source]
Overview:

Basic model of the connection classes, such as SlaveConnection and SlaveConnectionProxy, which are used widely in interaction module.

Example:
  • The following code shows a sample to correctly use slave connection

>>> connection = master.new_connection('cnn1,', '127.0.0.1', 2333)
>>> connection.connect()
>>> try:
>>>     pass # do anything you like
>>> finally:
>>>     connection.disconnect()
  • Another simple structure of the code above

>>> with master.new_connection('cnn1,', '127.0.0.1', 2333) as connection:
>>>     pass # do anything you like, connect and disconnect will be done automatically
close()[source]
Overview:

Alias for disconnect, for support context manager.

abstract connect()[source]
Overview:

Connect to slave end.

abstract disconnect()[source]
Overview:

Disconnect from slave end.

abstract new_task(data: Optional[Mapping[str, Any]] = None)[source]
Overview:

Send new task to slave end and receive task result from it.

Arguments:
  • data (Optional[Mapping[str, Any]]): Data of the new task

Returns:
  • result (Mapping[str, Any]): Result of the task processed by slave end

start()[source]
Overview:

Alias for connect, for supporting context manager.

SlaveConnection

class ding.interaction.master.connection.SlaveConnection(host: str, port: Optional[int] = None, https: bool = False, channel: Optional[int] = None, my_address: Optional[str] = None, token: Optional[str] = None, request_retries: Optional[int] = None, request_retry_waiting: Optional[float] = None)[source]
Overview:

Slave connection object, which need to directly interact with slave end.

__init__(host: str, port: Optional[int] = None, https: bool = False, channel: Optional[int] = None, my_address: Optional[str] = None, token: Optional[str] = None, request_retries: Optional[int] = None, request_retry_waiting: Optional[float] = None)[source]
Overview:

Constructor of SlaveConnection

Arguments:
  • host (str): Host of the slave server

  • port (Optional[int]): Port of the slave server (None means 7236)

  • https (bool): Use https or not

  • channel (Optional[int]): Channel id for the slave client.

  • my_address (Optional[str]): The address of current server (None will grep local ip automatically, this address will be used when connect to slave, the slave’s request will be send to this address, so please make sure the address can be achieved by slave)

  • token (Optional[str]): Token of this connection, it is a token for authenticate to the connection (None means this token would be randomly generated)

  • request_retries (Optional[int]): Max times for request retries (None means 5)

  • request_retry_waiting (Optional[float]): Sleep time before requests’ retrying (None means 1.0, unit: second)

close()
Overview:

Alias for disconnect, for support context manager.

connect()[source]
Overview:

Connect to slave end.

disconnect()[source]
Overview:

Disconnect from slave end.

property is_connected: bool
Overview:

Check connection status

Returns:
  • connected (bool): Whether this connection is still alive

new_task(data: Optional[Mapping[str, Any]] = None) ding.interaction.master.task.Task[source]
Overview:

Send new task to slave end and receive task result from it.

Arguments:
  • data (Optional[Mapping[str, Any]]): Data of the new task

Returns:
  • result (Mapping[str, Any]): Result of the task processed by slave end

start()
Overview:

Alias for connect, for supporting context manager.

SlaveConnectionProxy

class ding.interaction.master.connection.SlaveConnectionProxy(connection: ding.interaction.master.connection.SlaveConnection, after_connect: Optional[Callable] = None, after_disconnect: Optional[Callable] = None)[source]
Overview:

Proxy class for SlaveConnection class, which wraps the original methods.

__init__(connection: ding.interaction.master.connection.SlaveConnection, after_connect: Optional[Callable] = None, after_disconnect: Optional[Callable] = None)[source]
Overview:

Constructor of SlaveConnectionProxy

Arguments:
  • connection (SlaveConnection): Slave connection object

  • after_connect (Optional[Callable]): Behaviour going to be executed after connection established

  • after_disconnect (Optional[Callable]): Behaviour going to be executed after connection killed

close()
Overview:

Alias for disconnect, for support context manager.

connect()[source]
Overview:

Connect to slave end.

disconnect()[source]
Overview:

Disconnect from slave end.

property is_connected: bool
Overview:

Check connection status

Returns:
  • connected (bool): Whether this connection is still alive

new_task(data: Optional[Mapping[str, Any]] = None)[source]
Overview:

Send new task to slave end and receive task result from it.

Arguments:
  • data (Optional[Mapping[str, Any]]): Data of the new task

Returns:
  • result (Mapping[str, Any]): Result of the task processed by slave end

start()
Overview:

Alias for connect, for supporting context manager.