mirror of https://github.com/python/cpython
Use try-finally idiom in example for locks in multiprocessing
This commit is contained in:
parent
092b3cf671
commit
ee750d8f8d
|
@ -262,8 +262,10 @@ that only one process prints to standard output at a time::
|
||||||
|
|
||||||
def f(l, i):
|
def f(l, i):
|
||||||
l.acquire()
|
l.acquire()
|
||||||
print('hello world', i)
|
try:
|
||||||
l.release()
|
print('hello world', i)
|
||||||
|
finally:
|
||||||
|
l.release()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
lock = Lock()
|
lock = Lock()
|
||||||
|
|
Loading…
Reference in New Issue