interaction.master.master¶
Master¶
- class ding.interaction.master.master.Master(host: Optional[str] = None, port: Optional[int] = None, heartbeat_tolerance: Optional[float] = None, heartbeat_check_span: Optional[float] = None, request_retries: Optional[int] = None, request_retry_waiting: Optional[float] = None, channel: Optional[int] = None, my_address: Optional[str] = None)[source]¶
- Overview:
Interaction master end
- __contains__(name: str)[source]¶
- Overview:
Check if the active connection with the given name exist in this master client. Only connections still alive can be found here.
- Arguments:
name (
str): Name of the connection
- Returns:
output (
bool): Whether connection with the given name exist.
- __delitem__(name: str)[source]¶
- Overview:
Delete connection from this master client, and the deleted connection will be killed as well. Only connections still alive can be found here.
- Arguments:
name (
str): Name of the connection
- __getitem__(name: str)[source]¶
- Overview:
Try get the active connection with the given name. Only connections still alive can be found here.
- Arguments:
name (
str): Name of the connection
- Returns:
output (
bool): Connection object with the given name.
- __init__(host: Optional[str] = None, port: Optional[int] = None, heartbeat_tolerance: Optional[float] = None, heartbeat_check_span: Optional[float] = None, request_retries: Optional[int] = None, request_retry_waiting: Optional[float] = None, channel: Optional[int] = None, my_address: Optional[str] = None)[source]¶
- Overview:
Constructor of Master
- Arguments:
host (
Optional[str]): Host of the master server, based on flask (None means 0.0.0.0)port (
Optional[int]): Port of the master server, based on flask (None means 7235)heartbeat_tolerance: (
Optional[float]): Max time tolerance of the heartbeat missing (None means 15.0, minimum is 0.2, unit: second)heartbeat_check_span: (
Optional[float]): Timespan between the heartbeat status check (None means 1.0, minimum is 0.1, unit: second)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)channel (
Optional[int]): Channel id for the master client, please make sure that channel id is equal to the slave client’s channel id, or the connection cannot be established. (None means 0, but 0 channel is not recommended to be used in production)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)
- _after_connect(status_code: int, success: bool, code: int, message: Optional[str], data: Optional[Mapping[str, Any]]) → Any[source]¶
- Overview:
Behaviours executed after trying to establish connection. Default behaviour is to do nothing and return None, you can reload this method to change its behaviour.
- Arguments:
status_code (
int): Status code of the connection requestsuccess (
bool): Connect success or notcode (
int): Error code of the connection (0 means no error, other code can be found in SlaveErrorCode)message (
Optional[str]): Connection message of the connectiondata (
Optional[Mapping[str, Any]]): Connection data of the connection (returned by slave end)
- Returns:
output (
Any): Any return data, this data will be returned in connect method in connection object.
- _after_disconnect(status_code: int, success: bool, code: int, message: Optional[str], data: Optional[Mapping[str, Any]]) → Any[source]¶
- Overview:
Behaviours executed after trying to end connection. Default behaviour is to do nothing and return None, you can reload this method to change its behaviour.
- Arguments:
status_code (
int): Status code of the disconnection requestsuccess (
bool): Disconnect success or notcode (
int): Error code of the disconnection (0 means no error, other code can be found in SlaveErrorCode)message (
Optional[str]): Disconnection message of the disconnectiondata (
Optional[Mapping[str, Any]]): Disconnection data of the disconnection (returned by slave end)
- Returns:
output (
Any): Any return data, this data will be returned in disconnect method in connection object.
- _after_new_task(status_code: int, success: bool, code: int, message: Optional[str], data: Optional[Mapping[str, Any]]) → Any[source]¶
- Overview:
Behaviours executed after trying to create task. Default behaviour is to do nothing and return None, you can reload this method to change its behaviour, such as return the new task data.
- Arguments:
status_code (
int): Status code of the task requestsuccess (
bool): Disconnect success or notcode (
int): Error code of the task request (0 means no error, other code can be found in SlaveErrorCode)message (
Optional[str]): Task message of the task requestdata (
Optional[Mapping[str, Any]]): Task data of the task request (returned by slave end)
- Returns:
output (
Any): Any return data, this data will be returned in start method in task object.
- _before_connect() → Mapping[str, Any][source]¶
- Overview:
Behaviours executed before trying to establish connection, connection data is generated here as well. Default behaviour is to do nothing and return None, you can reload this method to change its behaviour. If exception raised in this method, the connection will be canceled.
- Returns:
output (
Mapping[str, Any]): Connection data
- _before_disconnect() → Mapping[str, Any][source]¶
- Overview:
Behaviours executed before trying to end connection, disconnection data is generated here as well. Default behaviour is to do nothing and return None, you can reload this method to change its behaviour. If exception raised in this method, the disconnection will be canceled.
- Returns:
output (
Mapping[str, Any]): Disconnection data
- _before_new_task(data: Optional[Mapping[str, Any]] = None) → Mapping[str, Any][source]¶
- Overview:
Behaviours executed before trying to create task. Default behaviour is to do nothing and return the original task data, you can reload this method to change its behaviour, such as preprocess the task data. If exception raised in this method, the task request will be canceled.
- Arguments:
data (
Optional[Mapping[str, Any]]): Original task data
- Returns:
output (
Mapping[str, Any]): Final task data, which will be send to slave end
- _error_connect(error: requests.exceptions.RequestException) → Any[source]¶
- Overview:
Behaviours executed after web error occurred in connection request. Default behaviour is to raise the error exception, you can reload this method to change its behaviour, such as return a proper value like None.
- Arguments:
error (
RequestException): Error raised from requests
- Returns:
output (
Any): Any data, this data will be returned in connect method in connection object
- _error_disconnect(error: requests.exceptions.RequestException)[source]¶
- Overview:
Behaviours executed after web error occurred in disconnection request. Default behaviour is to raise the error exception, you can reload this method to change its behaviour, such as return a proper value like None.
- Arguments:
error (
RequestException): Error raised from requests
- Returns:
output (
Any): Any data, this data will be returned in disconnect method in connection object
- _error_new_task(error: requests.exceptions.RequestException)[source]¶
- Overview:
Behaviours executed after web error occurred in task request. Default behaviour is to raise the error exception, you can reload this method to change its behaviour, such as return a proper value like None.
- Arguments:
error (
RequestException): Error raised from requests
- Returns:
output (
Any): Any data, this data will be returned in start method in task object
- join()[source]¶
- Overview:
Wait until current slave client is down completely. Here are the steps executed inside in order:
Wait until the http server thread down
Wait until the heartbeat check thread down
Wait until the result-processing thread down
- property my_address: str¶
- Overview:
Get my address property of current master client.
- Returns:
output (
str): My address which can be used to establish connection from slave end to here.
- new_connection(name: str, host: str, port: Optional[int] = None, https: bool = False) → ding.interaction.master.connection.SlaveConnectionProxy[source]¶
- Overview:
Create a new connection object to slave end (but the connection will be established immediately before connect method in connection object is called).
- Arguments:
name (
str): Name of the connection (this name is an unique label used in this master client)host (
str): Host of the slave endport (
Optional[int]): Port of the slave end (None means 7236)https (
bool): Use https to connect or not (Default is False)
- Returns:
output (
SlaveConnectionProxy): A connection object represents the connection from here to the slave end. More actions can be operated by this connection object.
- ping() → bool[source]¶
- Overview:
Ping the current http server, check if it still run properly.
- Returns:
output (
bool): The http server run properly or not. True means run properly, otherwise return False.