我正在尝试调试一个使用 pynetdicom 库的应用程序。我不确定该具体细节有多相关,但相关的是它大量使用多线程来运行后台套接字侦听器任务而不阻塞主线程。storescp.py 示例可用于重现这一点。
每当我放置遇到的断点时(无论遇到什么线程、主线程或子线程),我都会得到以下回溯:
Traceback (most recent call last):
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.7.0.2013012902/pysrc/pydevd.py", line 1397, in <module>
debugger.run(setup['file'], None, None)
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.7.0.2013012902/pysrc/pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/Users/alexw/Development/Python/kreport2/KReport2/dicomdatascraper.py", line 183, in <module>
oldDicomList = copy.copy(newData)
File "/Users/alexw/Development/Python/kreport2/KReport2/dicomdatascraper.py", line 183, in <module>
oldDicomList = copy.copy(newData)
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.7.0.2013012902/pysrc/pydevd_frame.py", line 135, in trace_dispatch
self.doWaitSuspend(thread, frame, event, arg)
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.7.0.2013012902/pysrc/pydevd_frame.py", line 25, in doWaitSuspend
self._args[0].doWaitSuspend(*args, **kwargs)
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.7.0.2013012902/pysrc/pydevd.py", line 832, in doWaitSuspend
self.processInternalCommands()
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.7.0.2013012902/pysrc/pydevd.py", line 360, in processInternalCommands
thread_id = GetThreadId(t)
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.7.0.2013012902/pysrc/pydevd_constants.py", line 140, in GetThreadId
return thread.__pydevd_id__
File "/Users/alexw/.virtualenvs/kreport2dev/devlibs/pynetdicom/source/netdicom/applicationentity.py", line 73, in __getattr__
obj = eval(attr)()
File "<string>", line 1, in <module>
NameError: name '__pydevd_id__' is not defined
我的想法是,也许,为了使事情正常工作,PyDev 猴子修补 a__pydevd_id__
到派生的线程中,但是未能将它们修补到这些线程中,因为它们实际上是子类而不是threading.Thread
(在这种情况下, worker 是class Association(threading.Thread):
) 的一个实例。
当然,我对 PyDev 的了解还不足以证实这个理论,或者修复它。互联网似乎也没有。
子类Thread
化是一种很少使用的模式,以至于在 PyDev 架构中根本没有考虑到它吗?如果不重新设计库,如何解决这个问题?