fugue.rpc
fugue.rpc.base
- class fugue.rpc.base.EmptyRPCHandler[source]
Bases:
RPCHandler
The class representing empty
RPCHandler
- class fugue.rpc.base.NativeRPCClient(server, key)[source]
Bases:
RPCClient
Native RPC Client that can only be used locally. Use
make_client()
to create this instance.- Parameters:
server (NativeRPCServer) – the parent
NativeRPCServer
key (str) – the unique key for the handler and this client
- class fugue.rpc.base.NativeRPCServer(conf)[source]
Bases:
RPCServer
Native RPC Server that can only be used locally.
- Parameters:
conf (Any) – the Fugue Configuration Tutorial
- make_client(handler)[source]
Add
handler
and correspondentNativeRPCClient
- Parameters:
handler (Any) – RPChandler like object
- Returns:
the native RPC client
- Return type:
- class fugue.rpc.base.RPCFunc(func)[source]
Bases:
RPCHandler
RPCHandler wrapping a python function.
- Parameters:
func (Callable) – a python function
- class fugue.rpc.base.RPCHandler[source]
Bases:
RPCClient
RPC handler hosting the real logic on driver side
- property running: bool
Whether the handler is in running state
- start()[source]
Start the handler, wrapping
start_handler()
- Returns:
the instance itself
- Return type:
- stop()[source]
Stop the handler, wrapping
stop_handler()
- Return type:
None
- class fugue.rpc.base.RPCServer(conf)[source]
Bases:
RPCHandler
,ABC
Server abstract class hosting multiple
RPCHandler
.- Parameters:
conf (Any) – the Fugue Configuration Tutorial
- invoke(key, *args, **kwargs)[source]
Invoke the correspondent handler
- Parameters:
key (str) – key of the handler
args (Any)
kwargs (Any)
- Returns:
the return value of the handler
- Return type:
Any
- abstract make_client(handler)[source]
Make a
RPCHandler
and return the correspondentRPCClient
- Parameters:
handler (Any) – RPChandler like object
- Returns:
the client connecting to the handler
- Return type:
- register(handler)[source]
Register the hander into the server
- Parameters:
handler (Any) – RPChandler like object
- Returns:
the unique key of the handler
- Return type:
str
- start_handler()[source]
Wrapper to start the server, do not override or call directly
- Return type:
None
- fugue.rpc.base.make_rpc_server(conf)[source]
Make
RPCServer
based on configuration. If ‘fugue.rpc.server` is set, then the value will be used as the server type for the initialization. Otherwise, aNativeRPCServer
instance will be returned- Parameters:
conf (Any) – the Fugue Configuration Tutorial
- Returns:
the RPC server
- Return type:
- fugue.rpc.base.to_rpc_handler(obj)[source]
Convert object to
RPCHandler
. If the object is alreadyRPCHandler
, then the original instance will be returned. If the object isNone
thenEmptyRPCHandler
will be returned. If the object is a python function thenRPCFunc
will be returned.- Parameters:
obj (Any) – RPChandler like object
- Returns:
the RPC handler
- Return type:
fugue.rpc.flask
- class fugue.rpc.flask.FlaskRPCClient(key, host, port, timeout_sec)[source]
Bases:
RPCClient
Flask RPC Client that can be used distributedly. Use
make_client()
to create this instance.- Parameters:
key (str) – the unique key for the handler and this client
host (str) – the host address of the flask server
port (int) – the port of the flask server
timeout_sec (float) – timeout seconds for flask clients
- class fugue.rpc.flask.FlaskRPCServer(conf)[source]
Bases:
RPCServer
Flask RPC server that can be used in a distributed environment. It’s required to set
fugue.rpc.flask_server.host
andfugue.rpc.flask_server.port
. Iffugue.rpc.flask_server.timeout
is not set, then the client could hang until the connection is closed.- Parameters:
conf (Any) – the Fugue Configuration Tutorial
Examples
conf = { "fugue.rpc.server": "fugue.rpc.flask.FlaskRPCServer", "fugue.rpc.flask_server.host": "127.0.0.1", "fugue.rpc.flask_server.port": "1234", "fugue.rpc.flask_server.timeout": "2 sec", } with make_rpc_server(conf).start() as server: server...
- make_client(handler)[source]
Add
handler
and correspondentFlaskRPCClient
- Parameters:
handler (Any) – RPChandler like object
- Returns:
the flask RPC client that can be distributed
- Return type: