Created
July 2, 2009 04:07
-
-
Save nelix/139265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading, os, sys, time | |
class autolock(threading._RLock): | |
__enter__ = threading._RLock.acquire | |
__leave__ = threading._RLock.release | |
def __except__(self, type, value, traceback): | |
self.release() | |
if type is KeyboardInterrupt: | |
self.interrupt = value | |
print "leaving with keyboard interrupt", os.getpid() | |
else: | |
raise type, value, traceback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment