This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author DragonSA
Recipients DragonSA
Date 2008-09-24.15:01:01
SpamBayes Score 1.1849312e-07
Marked as misclassified No
Message-id <1222268463.82.0.912581539287.issue3957@psf.upfronthosting.co.za>
In-reply-to
Content
Overview:
Add a generator that will revert the order applied to a with 
statement.  

Motivation:
Often with threaded applications one needs to do a certain task 
outside of a lock but while inside a greater block of code protected 
by a lock.  

e.g:
with lock:
  BLOCK1
  lock.release()
  try:
    BLOCK2
  finally:
    lock.acquire()
  BLOCK3

but with an inverter for a with statement it becomes:

with lock:
  BLOCK1
  with invert(lock):
    BLOCK2
  BLOCK3

[Of course there are many other possible uses for this...]

Implementation:
def invert(thing):
  thing.__exit__(None, None, None)
  yield thing
  thing.__enter__()

Issues:
Normal exception handling will not take place (however for locks and 
the like this is not an issue)
History
Date User Action Args
2008-09-24 15:01:03DragonSAsetrecipients: + DragonSA
2008-09-24 15:01:03DragonSAsetmessageid: <1222268463.82.0.912581539287.issue3957@psf.upfronthosting.co.za>
2008-09-24 15:01:02DragonSAlinkissue3957 messages
2008-09-24 15:01:01DragonSAcreate