Skip to content

Commit 31fe118

Browse files
HCharlieChangli Han
authored andcommitted
GH-116526 patch Synchronization between processes example
1 parent c951e25 commit 31fe118

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Doc/library/multiprocessing.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,15 @@ that only one process prints to standard output at a time::
301301
if __name__ == '__main__':
302302
lock = Lock()
303303

304+
processes = []
305+
304306
for num in range(10):
305-
Process(target=f, args=(lock, num)).start()
307+
p = Process(target=f, args=(lock, num))
308+
processes.append(p)
309+
p.start()
310+
311+
for p in processes:
312+
p.join()
306313

307314
Without using the lock output from the different processes is liable to get all
308315
mixed up.

0 commit comments

Comments
 (0)