mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Use try-finally idiom in example for locks in multiprocessing
This commit is contained in:
parent
092b3cf671
commit
ee750d8f8d
1 changed files with 4 additions and 2 deletions
|
|
@ -262,8 +262,10 @@ that only one process prints to standard output at a time::
|
|||
|
||||
def f(l, i):
|
||||
l.acquire()
|
||||
print('hello world', i)
|
||||
l.release()
|
||||
try:
|
||||
print('hello world', i)
|
||||
finally:
|
||||
l.release()
|
||||
|
||||
if __name__ == '__main__':
|
||||
lock = Lock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue