Python Multiprocessing Locks

If you change pool.apply_async to pool.apply, you get this exception:

Traceback (most recent call last):
  File "p.py", line 15, in <module>
    pool.apply(job, [l, i])
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 244, in apply
    return self.apply_async(func, args, kwds).get()
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
    raise self._value
RuntimeError: Lock objects should only be shared between processes through inheritance

pool.apply_async is just hiding it. I hate to say this, but using a global variable is probably the simplest way for your example. Let’s just hope the velociraptors don’t get you.

Leave a Comment