W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
The interpreter violently crashes with a segmentation fault, bus error, access violation,or other fatal error. You would like to get a Python traceback that shows you where yourprogram was running at the point of failure.
The faulthandler module can be used to help you solve this problem. Include thefollowing code in your program:
import faulthandlerfaulthandler.enable()
Alternatively, run Python with the -Xfaulthandler option such as this:
bash % python3 -Xfaulthandler program.py
Last, but not least, you can set the PYTHONFAULTHANDLER environment variable.With faulthandler enabled, fatal errors in C extensions will result in a Python trace‐back being printed on failures. For example:
Fatal Python error: Segmentation fault
Current thread 0x00007fff71106cc0:File “example.py”, line 6 in fooFile “example.py”, line 10 in barFile “example.py”, line 14 in spamFile “example.py”, line 19 in > Segmentation fault
Although this won’t tell you where in the C code things went awry, at least it can tell youhow it got there from Python.
The faulthandler will show you the stack traceback of the Python code executing atthe time of failure. At the very least, this will show you the top-level extension functionthat was invoked. With the aid of pdb or other Python debugger, you can investigate theflow of the Python code leading to the error.faulthandler will not tell you anything about the failure from C. For that, you willneed to use a traditional C debugger, such as gdb. However, the information from thefaulthandler traceback may give you a better idea of where to direct your attention.It should be noted that certain kinds of errors in C may not be easily recoverable. Forexample, if a C extension trashes the stack or program heap, it may render faulthandler inoperable and you’ll simply get no output at all (other than a crash). Obviously,your mileage may vary.
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: