rpc_sync¶
- paddle.distributed.rpc. rpc_sync ( to, fn, args=None, kwargs=None, timeout=- 1 ) [source]
-
Make a blocking RPC call to run function
fn
on workerto
. 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 the result of running
fn
withargs
andkwargs
.
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:8002") >>> ret = rpc.rpc_sync("worker0", add, args=(2, 3)) >>> rpc.shutdown()