Skip to content

Global

The main entry point for all remote operations, such as calling remote callbacks, waiting for remote processes, and obtaining additional information from remote sources.

Parameters:

Name Type Description Default
process_name Optional[str]

Global process name. If specified it is used as reference key to Node process. By default randomly generated hash is used as reference.

None
init_controller Optional[bool]

Flag that indicates whether Controller should be instantiated in current process

False
init_node Optional[bool]

Flag that indicates whether Node should be instantiated in current process

True
host Optional[str]

host to connect Controller/Node via tcp. If not provided then Global consider UNIX socket connection to be used.

None
port Optional[int]

Optional port to connect Controller/Node via tcp. If not provided random port will be chosen.

None
unix_sock_path Optional[os.PathLike]

Folder where UNIX socket will be created. If not provided default path is < tmp directory >/dafi/ where <tmp directory > is default temporary directory on system.

None
on_init Optional[Callable[[Global, str], Any]]

Function that will be executed once when Global object is initialized. on_init takes Global object as first argument

None
on_node_connect Optional[Callable[[Global, str], Any]]

Function that will be executed each time when connection to Controller is established (IOW it works only for Nodes). on_connect takes Global object as first argument

None
on_node_disconnect Optional[Callable[[Global, str], Any]]

Function that will be executed each time when connection to Controller is lost

None

call: LazyRemoteCall property

Returns instance of LazyRemoteCall that is used to trigger remote callback.

is_controller: bool property

Return True if controller is running in current process

registered_callbacks: Dict[str, List[str]] property

Return list of all registered callbacks along with process names where these callbacks are registered.

cancel_scheduled_task_by_uuid(remote_process: str, uuid: int) -> NoReturn

Cancel scheduled task by its uuid on remote process. Find out task uuid you can using get_scheduled_tasks method.

get_scheduled_tasks(remote_process: str)

Get all scheduled tasks that are running at this moment on remote process

Parameters:

Name Type Description Default
remote_process str

Name of Node

required

join() -> NoReturn

Join global to main thread. Don't use this method if you're running asynchronous application as it blocks event loop.

join_async() async

Async version of .join() method. Use this method if your application is asynchronous.

stop()

Stop all components (Node/Controller) that is running are current process

transfer_and_call(remote_process: str, func: Callable[..., Any], *args: Tuple[Any], **kwargs: Dict[Any, Any]) -> Union[Coroutine, Any]

Send function along with arguments to execute on remote process. This method has some limitations. For example you should import modules inside function as modules might be unavailable on remote.

Parameters:

Name Type Description Default
remote_process str

Name of node where function should be executed

required
args Tuple[Any]

Any positional arguments to execute function with.

()
kwargs Dict[Any, Any]

Any keyword arguments to execute function with.

{}
Example

import os

from daffi import Global

async def get_remote_pid(): import os return os.getpid()

g = Global() g.transfer_and_call("node_name", get_remote_pid)

wait_function(func_name: str) -> NoReturn

Wait particular remote callback by name to be available. This method is useful when callback with the same name is registered on different nodes and you need at leas one node to be available.

Parameters:

Name Type Description Default
func_name str

Name of remote callback to wait.

required

wait_function_async(func_name: str) -> NoReturn async

Wait particular remote callback by name to be available (async version). This method is useful when callback with the same name is registered on different nodes and you need at leas one node to be available.

Parameters:

Name Type Description Default
func_name str

Name of remote callback to wait.

required

wait_process(process_name: str) -> NoReturn

Wait particular Node to be alive.

Parameters:

Name Type Description Default
process_name str

Name of Node

required

wait_process_async(process_name: str) -> NoReturn async

Wait particular Node to be alive (async version).

Parameters:

Name Type Description Default
process_name str

Name of Node

required