【发布时间】:2011-07-21 18:08:36
【问题描述】:
所以,我有一个多线程 python 程序,它目前正遭受死锁。我打算通过子类化 threading.Lock 对象来记录锁获取:
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)
当我尝试运行程序时,我收到以下错误:
class DebugLock(threading.Lock):
TypeError: Error when calling the metaclass bases
cannot create 'builtin_function_or_method' instances
所以,我的问题是双重的:
是否可以继承 Lock 对象来做我正在做的事情?
如果不是,那么在 python 中调试死锁的最佳方法是什么?
注意:我没有编写任何 Python 扩展。有一个类似的问题:How to debug deadlock with python? 但是,它处理编译 C++ 代码和使用 GDB,因为我的代码是纯 python,所以我不能这样做。
【问题讨论】:
标签: python multithreading oop thread-safety deadlock