So, I've got a multithreaded python program, which is currently suffering from deadlock. I was going to log lock acquiring by subclassing threading.Lock objects:
import traceback
class DebugLock(threading.Lock):
def acquire(self):
print >>sys.stderr, "acquired", self
#traceback.print_tb
threading.Lock.acquire(self)
def release(self):
print >>sys.stderr, "released", self
#traceback.print_tb
threading.Lock.release(self)
When I try to run the program, I get the following error:
class DebugLock(threading.Lock):
TypeError: Error when calling the metaclass bases
cannot create 'builtin_function_or_method' instances
So, my question is twofold:
Is it possible to subclass Lock objects to do what I'm doing?
If not, what is the best way to debug deadlock in python?
Note: I'm not writing any Python extension. There's a similar question: How to debug deadlock with python? However, it deals with compiling C++ code and using GDB, which I can't do since my code is pure python.