fugue.rpc#

fugue.rpc.base#

class fugue.rpc.base.EmptyRPCHandler[source]#

Bases: fugue.rpc.base.RPCHandler

The class representing empty RPCHandler

class fugue.rpc.base.NativeRPCClient(server, key)[source]#

Bases: fugue.rpc.base.RPCClient

Native RPC Client that can only be used locally. Use make_client() to create this instance.

Parameters
class fugue.rpc.base.NativeRPCServer(conf)[source]#

Bases: fugue.rpc.base.RPCServer

Native RPC Server that can only be used locally.

Parameters

conf (Any) – the Fugue Configuration Tutorial

make_client(handler)[source]#

Add handler and correspondent NativeRPCClient

Parameters

handler (Any) – RPChandler like object

Returns

the native RPC client

Return type

fugue.rpc.base.RPCClient

start_server()[source]#

Do nothing

Return type

None

stop_server()[source]#

Do nothing

Return type

None

class fugue.rpc.base.RPCClient[source]#

Bases: object

RPC client interface

class fugue.rpc.base.RPCFunc(func)[source]#

Bases: fugue.rpc.base.RPCHandler

RPCHandler wrapping a python function.

Parameters

func (Callable) – a python function

class fugue.rpc.base.RPCHandler[source]#

Bases: fugue.rpc.base.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

fugue.rpc.base.RPCHandler

start_handler()[source]#

User implementation of starting the handler

Return type

None

stop()[source]#

Stop the handler, wrapping stop_handler()

Return type

None

stop_handler()[source]#

User implementation of stopping the handler

Return type

None

class fugue.rpc.base.RPCServer(conf)[source]#

Bases: fugue.rpc.base.RPCHandler, abc.ABC

Server abstract class hosting multiple RPCHandler.

Parameters

conf (Any) – the Fugue Configuration Tutorial

property conf: triad.collections.dict.ParamDict#

Config initialized this instance

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 correspondent RPCClient

Parameters

handler (Any) – RPChandler like object

Returns

the client connecting to the handler

Return type

fugue.rpc.base.RPCClient

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

abstract start_server()[source]#

User implementation of starting the server

Return type

None

stop_handler()[source]#

Wrapper to stop the server, do not override or call directly

Return type

None

abstract stop_server()[source]#

User implementation of stopping the server

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, a NativeRPCServer instance will be returned

Parameters

conf (Any) – the Fugue Configuration Tutorial

Returns

the RPC server

Return type

fugue.rpc.base.RPCServer

fugue.rpc.base.to_rpc_handler(obj)[source]#

Convert object to RPCHandler. If the object is already RPCHandler, then the original instance will be returned. If the object is None then EmptyRPCHandler will be returned. If the object is a python function then RPCFunc will be returned.

Parameters

obj (Any) – RPChandler like object

Returns

the RPC handler

Return type

fugue.rpc.base.RPCHandler

fugue.rpc.flask#

class fugue.rpc.flask.FlaskRPCClient(key, host, port, timeout_sec)[source]#

Bases: fugue.rpc.base.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: fugue.rpc.base.RPCServer

Flask RPC server that can be used in a distributed environment. It’s required to set fugue.rpc.flask_server.host and fugue.rpc.flask_server.port. If fugue.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 correspondent FlaskRPCClient

Parameters

handler (Any) – RPChandler like object

Returns

the flask RPC client that can be distributed

Return type

fugue.rpc.base.RPCClient

start_server()[source]#

Start Flask RPC server

Return type

None

stop_server()[source]#

Stop Flask RPC server

Return type

None