Use try-finally idiom in example for locks in multiprocessing

This commit is contained in:
Andrew Svetlov 2014-07-02 07:21:03 +03:00
parent 092b3cf671
commit ee750d8f8d
1 changed files with 4 additions and 2 deletions

View File

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