Skip to content

Instantly share code, notes, and snippets.

@nelix
Created July 2, 2009 04:07
Show Gist options
  • Save nelix/139265 to your computer and use it in GitHub Desktop.
Save nelix/139265 to your computer and use it in GitHub Desktop.
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