16

Oddly, in debug mode, if the script is stopped (via a breakpoint) where the segfault would normally occur (without the breakpoint), and then resumed, the segmentation fault will not happen. Very strange right?

This project uses pycharm and pygame. The OS is windows 10. This project contains ~1500 lines of code across 8 modules, and debugging worked great until now.

The segmentation fault does not happen when running the script normally (not in debug). Here is the output of the terminal when a seg fault occurs:

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)

The only thing I can think of right away is the use of forward slashes for the module main.py . The stack frame below it seems to consider filenames:

    #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)

Is the debugger getting the filename wrong? That's the only hint I have. I'm new to python development. Even if you don't have a complete answer, any help/tips would be greatly appreciated.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Frank Larry
  • 161
  • 6
  • 17
    Through sheer luck, I've been able to avoid this seg fault by changing a single setting in python debugger. I checked the box "Collect run-time types information for code insight". With this box checked, the seg fault will not happen (so far), with this box unchecked, the debugger will crash. Why though? – Frank Larry Dec 26 '21 at 06:54
  • If it is possible for you - send the project code to PyCharm support at pycharm-support@jetbrains.com. It is hard to tell what is wrong without it, unfortunately. In general - debug run != pure run. The debugger uses CPython API to interact with the Python process - there might be issues with it or a bug in the debugger itself. – Pavel Karateev Dec 27 '21 at 08:26
  • 1
    Oh my GOD... I'm in the same situation!! I'm using macOS catalina 10.15.7, python 3.10.4, Pycharm 2022.1 (PY-221.5080.212) and it crashes ONLY in debug. And I tried "Collect run-time types information for code insight" It works!!! you saved my life thank you so much! (I've re-installed python and pycharm several times it was no good :( ) – Jerry Apr 28 '22 at 00:48
  • 1
    As you mentioned in the comment checking the box "Collect run-time types information for code insight" worked for me. – theredcomet Apr 29 '22 at 05:46
  • Mac OS Monterey (12.5), Pycharm 2022.1.4, Python 3.10.5, M1 MBP ... exact same issue that popped up suddenly: debug mode crashes where running the script works fine. Checking the "Collect run-time types information for code insight" fixed it! Big thanks from me. – seayak Jul 28 '22 at 01:29
  • 1
    The solution in Frank's comment worked for me as well. @FrankLarry you should post as an answer so this gets more visibility. – Fiver Jul 30 '22 at 17:55
  • Same here. Run-time types seem to be very useful indeed. I figured out the connection between the bug and the checkbox with luck. This post must be hard to find for anybody who is suffering of the issue. – Ville Laitila Dec 21 '22 at 17:46

2 Answers2

13

Also worked for me ! Thanks a lot @FrankLarry

For those who didn't find it:

Pycharm Preferences -> Python Debugger -> Collect run-time types...

Just tick this option.

madaniel
  • 161
  • 1
  • 6
0

In my case the SIGSEGV was caused by stack overflow due to endless recursive call of the __getattr__ method. The call was initiated by the data window (which was trying to display variable values when break point was reached).

But the callstack and the exception message was not printed to the debug window (because it was not caused by my python application, but by PyCharm) so it was not easy to find the real reason.

It helped me to switch "Variables Loading Policy" to "On demand" value in Debug window settings.

eNca
  • 1,043
  • 11
  • 21