mutiprocessing, manager, list & threading ?

John Nagle nagle at animats.com
Tue Dec 28 11:39:12 EST 2010


On 12/28/2010 1:38 AM, mika.saari at wipsl.com wrote:
> Hi,
>
>    Testing if I could be able to use multiprocessing BaseManager to manage
> list of instance pointers between processes. If my intance inherits
> Thread, I get pickling error about _thread.lock.

     The "multiprocessing" module works by running completely separate
programs which communicate by copying data back and forth through
pipes or sockets.  You can't share thread locks.  (There's a gimmick
that lets you put an array of fixed type and size in shared memory,
but that's very limited, because Python's locking doesn't really
understand multiprocessing.)

     If you need to access a list from several processes, have
one process own the list, and use a Manager from the multiprocessing
module to create a proxy to access the list from the other processes.
Note that this is slower than regular list access.  But if you just
need to have a to-do list that feeds multiple processes, that's a way
to do it.

					John Nagle



More information about the Python-list mailing list