>>>>> gvv <gvver...@gmail.com> (G) wrote: >G> Hi All, >G> I am trying to understand multiprocessing, but I am getting a Runtime >G> error on the >G> code below. What am I missing or doing wrong? >G> Error is: >G> RuntimeError: Lock objects should only be shared between processes >G> through inheritance [code deleted]
I guess you can't share locks (and probably other objects) between processes from a Pool. Maybe because there is no direct parent-child relation or so (there is a separate thread involved). There is nothing in the doc that explicitely forbids it AFAICT but it says that you have to be careful with sharing. But it could be a bug. You can do it with a manager, however, but this involves an additional process under the hood. if __name__ == "__main__": manager = multiprocessing.Manager() lock = manager.Lock() pool = multiprocessing.Pool(processes=5) for i in xrange(100): pool.apply_async(func=RunFunc, args=(i,lock)) pool.close() pool.join() -- Piet van Oostrum <p...@cs.uu.nl> URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list