Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee750d8

Browse files
committed
Use try-finally idiom in example for locks in multiprocessing
1 parent 092b3cf commit ee750d8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Doc/library/multiprocessing.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ that only one process prints to standard output at a time::
262262

263263
def f(l, i):
264264
l.acquire()
265-
print('hello world', i)
266-
l.release()
265+
try:
266+
print('hello world', i)
267+
finally:
268+
l.release()
267269

268270
if __name__ == '__main__':
269271
lock = Lock()

0 commit comments

Comments
 (0)