Skip to content Skip to sidebar Skip to footer

Python Multiprocessing.managers.basemanager Running Registered Callable Function Sequentially

I am working with a remote manager provided by Python's multiprocessing library. I have setup a remote server using BaseManager, to which multiple clients connect simultaneously. U

Solution 1:

the callable you're registering is a 'creation' method and these are always run in a locked context, but the object it returns is automatically proxied and any methods invoked on it aren't automatically locked

in your demo code, I'd change:

def server():
    distance_time=DistanceTime()
    BaseManager.register('get_distance_time', callable=distance_time.get_distance_time)

to be:

def server():
    distance_time = DistanceTime()
    BaseManager.register('DistanceTime', lambda: distance_time)

and then use this as:

distance_time = manager.DistanceTime()
a = executor.submit(distance_time.get_distance_time)
b = executor.submit(distance_time.get_distance_time)
c = executor.submit(distance_time.get_distance_time)

which should allow everything go in parallel. I've not actually tested this, but will if you say this doesn't work...

not that it matters here, but I generally feel it's better to register these sorts of things in a separate/derived Manager

Post a Comment for "Python Multiprocessing.managers.basemanager Running Registered Callable Function Sequentially"