]> granicus.if.org Git - python/commitdiff
Use try-finally idiom in example for locks in multiprocessing
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Wed, 2 Jul 2014 04:21:03 +0000 (07:21 +0300)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Wed, 2 Jul 2014 04:21:03 +0000 (07:21 +0300)
Doc/library/multiprocessing.rst

index 5fac730801761f47a55d9564624fa15e66cda6e9..276339842cd077e6cb457432473c37355f122ca1 100644 (file)
@@ -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()