Starting debugger on errors in threads
I'm using following trick to get debugger started on error Starting python debugger automatically on error
Any idea how to make this also work for errors that happen in newly created threads? I'm using thread pool, something like http://code.activestate.com/recipes/577187-python-thread-pool/
I'd say inject that code in the beginning of each Thread's run().
If you don't want to change that code, you could do monkeypatch it eg like this:
Worker.run = lambda *a: [init_pdb(), Worker.run(*a)][-1]
Or like this:
def wrapper(*a):
# init pdb here
Worker.run(*a)
Worker.run = wrapper
If you wanna go real hardcore, you can override threading.Thread.start, or possibly threading.Thread altogether before you import other modules, eg:
class DebuggedThread(threading.Thread):
def __init__(self):
super(DebuggedThread, self).__init__()
self._real_run = self.run
self.run = self._debug_run
def _debug_run(self):
# initialize debugger here
self._real_run()
threading.Thread = DebuggedThread
链接地址: http://www.djcxy.com/p/39408.html
上一篇: 在C级别上如何实现PHP数组?
下一篇: 启动线程中的错误调试器