rpc_async

paddle.distributed.rpc. rpc_async ( to, fn, args=None, kwargs=None, timeout=- 1 ) [source]

Make a non-blocking RPC call to run function fn on worker to. Attention: Users must use this API in a secure network environment.

Parameters
  • to (str) – name of the destination worker.

  • fn (fn) – a callable function, such as Python callables.

  • args (tuple, optional) – the argument tuple for the fn invocation, default is None.

  • kwargs (dict, optional) – is a dictionary of keyword arguments for the fn invocation, default is None.

  • timeout (int, optional) – timeout in seconds to use for this RPC. If the RPC does not complete in this amount of time, an exception indicating it has timed out will be raised. A value less than or equal to 0 indicates an infinite timeout, i.e. a timeout error will never be raised. The default value is -1.

Returns

Returns a FutureWrapper object that can be waited on. When completed, the return value of fn on args and kwargs can be got by fut.wait().

Examples

>>> 
>>> import paddle.distributed.rpc as rpc

>>> def add(a, b):
...     return a + b

>>> rpc.init_rpc("worker0", rank=0, world_size=1,
...         master_endpoint="127.0.0.1:8003")

>>> fut = rpc.rpc_async("worker0", add, args=(2, 3))
>>> print(fut.wait())
5

>>> rpc.shutdown()