multiprocessing, SyncManager, dict() of Locks possible?

rooster 808 rich.aloha at gmail.com
Mon Sep 28 12:17:48 EDT 2009


I'm trying to work out a multiple readers, one writer scenerio with a
bunch of objects. Basically "foo" objects are shared across processes.
Each foo object has a .lock variable, which holds a Mutex. In
creation, I'd like to call the SyncManager, get the dict() object
which hold object_ids->lock mappings (so we can create a lock per
object only once)...

Creating the lock map happens  like this:

if not object_locks.has_key(object_id):
    new_lock = manager.Lock()
   manager.object_locks.update({ object_id: new_lock})
Everything seems fine, except, on retrieval of the
SyncManager.get_object_locks().get(object_id)  I get a

Unserializable message: ('#RETURN', <thread.lock object at 0x177b190>)

I had thought the multiprocessing Lock was serializable and shared.

Any other alternatives versus a global lock around all object writes?




More information about the Python-list mailing list