[docs] Bug: multiprocessing documentation

Theo Walker naroom at gmail.com
Tue May 21 20:14:36 CEST 2013


http://docs.python.org/2/library/multiprocessing.html

Section:
16.6.1.3. Synchronization between processes

Sample code doesn't work, as processes may exit before releasing the lock.
Adding a join() on each process fixes the problem. Corrected code below:

from multiprocessing import Process, Lock


def f(l, i):

#single process executes the block at a time

l.acquire()

print 'hello world', i

l.release()


if __name__ == '__main__':

lock = Lock()


 #spawn 10 processes, each with an arg that says their index

for num in range(10):

p = Process(target=f, args=(lock, num))

p.start()

p.join()


Thanks for maintaining the doc, for the betterment of all mankind!

--Theo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20130521/bce0b8c0/attachment-0001.html>


More information about the docs mailing list