问题表现
项目正常run没有问题,但是debug启动的时候报:module 'thread' has no attribute 'start_new_thread',具体错误如下图:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 2199, in <module>
main()
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 2181, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1451, in run
self.prepare_to_run()
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1339, in prepare_to_run
self.patch_threads()
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1355, in patch_threads
patch_thread_modules()
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_monkey.py", line 886, in patch_thread_modules
patch_thread_module(t)
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_monkey.py", line 849, in patch_thread_module
_original_start_new_thread = thread_module._original_start_new_thread = thread_module.start_new_thread
AttributeError: module 'thread' has no attribute 'start_new_thread'
原因有两种情况:
- 模块中没有这个属性
- 项目里包含一个叫thread.py的文件或者thread的包名,重命名一下即可。(我的是这个问题)