python/pycharm项目在调试模式下产生分段错误,但在运行模式下不会产生分段错误

Fra*_*rry 20 python debugging segmentation-fault pycharm

奇怪的是,在调试模式下,如果脚本在通常会发生段错误(没有断点)的地方停止(通过断点),然后恢复,则不会发生段错误。很奇怪吧?

本项目使用pycharm和pygame。操作系统是 windows 10。该项目包含跨 8 个模块的约 1500 行代码,到目前为止调试效果很好。

正常运行脚本时(不在调试中)不会发生分段错误。这是发生段故障时终端的输出:

Fatal Python error: pygame_parachute: (pygame parachute) Segmentation Fault
Python runtime state: initialized

#some other threads here
Thread 0x0000490c (most recent call first):
... a long stack trace
Thread 0x00002c98 (most recent call first):
... a long stack trace
Thread 0x000048ec (most recent call first):
... a long stack trace

Current thread 0x000020d0 (most recent call first):
  File "C:\Users\Solaire\PycharmProjects\Game2\ai.py", line 60 in do_ai
  **File "C:/Users/Solaire/PycharmProjects/Game2/main.py", line 45 in <module>**
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18 in execfile
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1483 in _exec
Extension modules:
 ...lots of extensions...

Process finished with exit code -1073740791 (0xC0000409)
Run Code Online (Sandbox Code Playgroud)

我立即能想到的唯一一件事就是在模块 main.py 中使用正斜杠。下面的堆栈框架似乎考虑了文件名:

    #execute the script (note: it's important to compile first to have the filename set in debug mode)
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
Run Code Online (Sandbox Code Playgroud)

调试器获取的文件名是否错误?这是我唯一的提示。我是 python 开发新手。即使您没有完整的答案,任何帮助/提示将不胜感激。

小智 20

也为我工作过!非常感谢@FrankLarry

对于那些没有找到它的人:

Pycharm 首选项 -> Python 调试器 -> 收集运行时类型...

只需勾选此选项即可。