- class compas.rpc.Proxy(package=None, python=None, url='http://127.0.0.1', port=1753, service=None, max_conn_attempts=100, autoreload=True, capture_output=True)
Create a proxy object as intermediary between client code and remote functionality.
This class is a context manager, so when used in a
withstatement, it ensures the remote proxy server is stopped and disposed correctly.
However, if the proxy server is left open, it can be re-used for a follow-up connection, saving start up time.
str:, optional) – The base package for the requested functionality. Default is None, in which case a full path to function calls should be provided.
str:, optional) – The python executable that should be used to execute the code. Default is
str:, optional) – The server address. Default is
int:, optional) – The port number on the remote server. Default is
str:, package name to start server.) – Default is
int, optional) – Amount of attempts to connect to RPC server before time out.
Trueto automatically reload the proxied package if changes are detected.) – This is particularly useful during development. The server will monitor changes to the files that were loaded as a result of accessing the specified package and if any change is detected, it will unload the module, so that the next invocation uses a fresh version.
Trueto capture the stdout/stderr output of the remote process, otherwise
False.) – In general,
Truewhen using a
pythonwas executable (default).
If the server is your localhost, which will often be the case, it is better to specify the address explicitly (
'http://127.0.0.1') because resolving localhost takes a surprisingly significant amount of time.
The service will make the correct (version of the requested) functionality available even if that functionality is part of a virtual environment. This is because it will use the specific python interpreter for which the functionality is installed to start the server.
If possible, the proxy will try to reconnect to an already existing service
Minimal example showing connection to the proxy server, and ensuring the server is disposed after using it:
from compas.rpc import Proxy with Proxy('compas.numerical') as numerical: pass
Restart the server.
Start the remote server.
Stop the remote server and terminate/kill the python process that was used to start it.