fiber.managers

Managers and proxy objects enable multiprocessing to support shared storage, which is critical to distributed systems. Usually, this function is handled by external storage systems like Cassandra, Redis, etc. Fiber instead provides built-in in-memory storage for applications to use (based on multiprocessing.managers). The interface is the same as multiprocessing's Manager type.

BaseManager

BaseManager(self,
            address=None,
            authkey=None,
            serializer='pickle',
            ctx=None)

A Base class for people to create customized managers. Equivalent to multiprocessing.managers.BaseManager but can work on a computer cluster.

The API of this class is the same as multiprocessing.managers.BaseManager

SyncManager

SyncManager(self,
            address=None,
            authkey=None,
            serializer='pickle',
            ctx=None)

Subclass of BaseManager which supports a number of shared object types.

The types that are supported include:

SyncManager is exposed as fiber.Manager. You can also use fiber.managers.SyncManager directly. The difference is that fiber.Manager will start the newly created manager and when using SyncManager, the user need to call the start() method of the manager explicitly.

fiber.Manager example:

manager = fiber.Manager()
d = manager.dict()
d["name"] = "managed_dict"
print(d)

fiber.managers.SyncManager example:

manager = fiber.managers.SyncManager()
manager.start()
l = manager.list()
l.append("x")
print(l)

AsyncManager

AsyncManager(self,
             address=None,
             authkey=None,
             serializer='pickle',
             ctx=None)

Asynchronous version of BaseManager. Currently, this type doesn't register any shared object types like SyncManager, it is more meant to be used as a base class for customized managers.

The API of the class is the same as SyncManager and multiprocessing.managers.BaseManager

Example usage:

from fiber.managers import AsyncManager

class Calculator():
    def add(self, a, b):
        return a + b

class MyManager(AsyncManager):
    pass

MyManager.register("Calculator", Calculator)
manager = MyManager()
manager.start()

calc = manager.Calculator()
res = calc.add(10, 32)
print(type(res)) # fiber.managers.AsyncProxyResult
print(res.get()) # 42