[docs] Bug: multiprocessing documentation

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


Section: 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


print 'hello world', i


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))



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

-------------- 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