A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/095893.html below:

Exceptions and locks

Exceptions and locks Exceptions and locksMatthew Dixon Cowles matt at mondoinfo.com
Tue Apr 10 13:19:15 EDT 2001
On Tue, 10 Apr 2001 18:55:36 +0200, Michael Ströder
<michael at stroeder.com> wrote:

>I'm currently doing something like this code below to make sure that
>locks are released also in case of any exception raised:
>
>my_lock = threading.Lock()
>
>my_lock.acquire()
>try:
>  ..some single action..
>except:
>  my_lock.release()
>  raise
>my_lock.release()
>
>But this looks crude to me. Any more elegant way of doing this?

This is just the sort of situation that the try...finally sequence was
designed for. See:

http://www.python.org/doc/current/ref/try.html

and have a look at the last two paragraphs.

Regards,
Matt

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4