New submission from David Naylor <[EMAIL PROTECTED]>: 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) ---------- components: Library (Lib) messages: 73715 nosy: DragonSA severity: normal status: open title: [contextlib] Reverse order of locking type: feature request versions: Python 2.6, Python 3.0 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3957> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com