A RetroSearch Logo

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

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-April/064243.html below:

[Python-Dev] Proposed addition to threading module

[Python-Dev] Proposed addition to threading module - releasedNick Coghlan ncoghlan at iinet.net.au
Mon Apr 24 05:44:52 CEST 2006
Do we want to add a "released" context manager to the threading module for 
2.5? It was mentioned using the name "unlocked" in PEP 343, but never spelt out:

class released(object):
     def __init__(self, lock):
         self.lock = lock
     def __enter__(self):
         self.lock.release()
     def __exit__(self, *exc_info):
         self.lock.acquire()

(This context manager is the equivalent of PEP 319's asynchronize keyword)

Usage would be:

   from threading import RLock, released

   sync_lock = RLock()

   def thread_safe():
      with sync_lock:
          # This is thread-safe
          with released(sync_lock):
              # Perform long-running or blocking operation
              # that doesn't need to hold the lock
          # We have the lock back here

(This particular example could be handled by two separate "with sync_lock" 
statements with the asynchronous operation between them, but other cases put 
the asynchronous operation inside a loop or a conditional statement which 
means that particular trick won't work).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
More information about the Python-Dev 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