Protocol¶
The RPyC protocol
-
exception
rpyc.core.protocol.PingError[source]¶ The exception raised should
Connection.ping()fail
-
rpyc.core.protocol.DEFAULT_CONFIG= {'allow_all_attrs': False, 'allow_delattr': False, 'allow_exposed_attrs': True, 'allow_getattr': True, 'allow_pickle': False, 'allow_public_attrs': False, 'allow_safe_attrs': True, 'allow_setattr': False, 'connid': None, 'credentials': None, 'endpoints': None, 'exposed_prefix': 'exposed_', 'import_custom_exceptions': False, 'include_local_traceback': True, 'instantiate_custom_exceptions': False, 'instantiate_oldstyle_exceptions': False, 'log_exceptions': True, 'logger': None, 'propagate_KeyboardInterrupt_locally': True, 'propagate_SystemExit_locally': False, 'safe_attrs': {'__isub__', '__delitem__', '__len__', '__mod__', '__sub__', '__rdivmod__', '__rfloordiv__', '__length_hint__', '__divmod__', '__invert__', '__itruediv__', '__irshift__', '__le__', '__lt__', '__hash__', '__rmul__', '__rsub__', '__idiv__', '__enter__', '__long__', '__eq__', '__float__', '__setitem__', '__ge__', '__rlshift__', '__contains__', '__ifloordiv__', '__oct__', '__rdiv__', '__pow__', '__radd__', '__add__', '__str__', '__rpow__', 'next', '__neg__', '__rxor__', '__rshift__', '__ipow__', '__next__', '__iadd__', '__repr__', '__ilshift__', '__rrshift__', '__new__', '__truediv__', '__hex__', '__iand__', '__getslice__', '__cmp__', '__ixor__', '__setslice__', '__gt__', '__exit__', '__xor__', '__doc__', '__mul__', '__ior__', '__ne__', '__and__', '__ror__', '__div__', '__imod__', '__rtruediv__', '__getitem__', '__or__', '__index__', '__lshift__', '__delslice__', '__abs__', '__nonzero__', '__floordiv__', '__int__', '__pos__', '__rand__', '__iter__', '__bool__', '__imul__', '__rmod__'}, 'sync_request_timeout': 30}¶ The default configuration dictionary of the protocol. You can override these parameters by passing a different configuration dict to the
Connectionclass.Note
You only need to override the parameters you want to change. There’s no need to repeat parameters whose values remain unchanged.
Parameter Default value Description allow_safe_attrsTrueWhether to allow the use of safe attributes (only those listed as safe_attrs)allow_exposed_attrsTrueWhether to allow exposed attributes (attributes that start with the exposed_prefix)allow_public_attrsFalseWhether to allow public attributes (attributes that don’t start with _)allow_all_attrsFalseWhether to allow all attributes (including private) safe_attrsset([...])The set of attributes considered safe exposed_prefix"exposed_"The prefix of exposed attributes allow_getattrTrueWhether to allow getting of attributes ( getattr)allow_setattrFalseWhether to allow setting of attributes ( setattr)allow_delattrFalseWhether to allow deletion of attributes ( delattr)allow_pickleFalseWhether to allow the use of pickleinclude_local_tracebackTrueWhether to include the local traceback in the remote exception instantiate_custom_exceptionsFalseWhether to allow instantiation of custom exceptions (not the built in ones) import_custom_exceptionsFalseWhether to allow importing of exceptions from not-yet-imported modules instantiate_oldstyle_exceptionsFalseWhether to allow instantiation of exceptions which don’t derive from Exception. This is not applicable for Python 3 and later.propagate_SystemExit_locallyFalseWhether to propagate SystemExitlocally (kill the server) or to the other party (kill the client)propagate_KeyboardInterrupt_locallyFalseWhether to propagate KeyboardInterruptlocally (kill the server) or to the other party (kill the client)loggerNoneThe logger instance to use to log exceptions (before they are sent to the other party) and other events. If None, no logging takes place.connidNoneRuntime: the RPyC connection ID (used mainly for debugging purposes) credentialsNoneRuntime: the credentails object that was returned by the server’s authenticator or NoneendpointsNoneRuntime: The connection’s endpoints. This is a tuple made of the local socket endpoint ( getsockname) and the remote one (getpeername). This is set by the server upon accepting a connection; client side connections do no have this configuration option set.sync_request_timeout30Default timeout for waiting results
-
class
rpyc.core.protocol.Connection(service, channel, config={}, _lazy=False)[source]¶ The RPyC connection (AKA protocol).
Parameters: - service – the
Serviceto expose - channel – the
Channelover which messages are passed - config – the connection’s configuration dict (overriding parameters
from the
default configuration) - _lazy – whether or not to initialize the service with the creation of
the connection. Default is True. If set to False, you will
need to call
_init_service()manually later
-
closed¶ Indicates whether the connection has been closed or not
-
ping(data=None, timeout=3)[source]¶ Asserts that the other party is functioning properly, by making sure the data is echoed back before the timeout expires
Parameters: - data – the data to send (leave
Nonefor the default buffer) - timeout – the maximal time to wait for echo
Raises: PingErrorif the echoed data does not match- data – the data to send (leave
-
poll(timeout=0)[source]¶ Serves a single transaction, should one arrives in the given interval. Note that handling a request/reply may trigger nested requests, which are all part of a single transaction.
Returns: Trueif a transaction was served,Falseotherwise
-
serve(timeout=1)[source]¶ Serves a single request or reply that arrives within the given time frame (default is 1 sec). Note that the dispatching of a request might trigger multiple (nested) requests, thus this function may be reentrant.
Returns: Trueif a request or reply were received,Falseotherwise.
-
poll_all(timeout=0)[source]¶ Serves all requests and replies that arrive within the given interval.
Returns: Trueif at least a single transaction was served,Falseotherwise
-
sync_request(handler, *args)[source]¶ Sends a synchronous request (waits for the reply to arrive)
Raises: any exception that the requets may be generated Returns: the result of the request
-
async_request(handler, *args, **kwargs)[source]¶ Send an asynchronous request (does not wait for it to finish)
Returns: an rpyc.core.async.AsyncResultobject, which will eventually hold the result (or exception)
-
root¶ Fetches the root object (service) of the other party
- service – the