問題描述
我正在 Python 中實現 Kosaraju 的強連通分量 (SCC) 圖搜索算法.
I am implementing Kosaraju's Strong Connected Component(SCC) graph search algorithm in Python.
該程序在小數據集上運行良好,但是當我在超大圖(超過 800,000 個節點)上運行它時,它顯示Segmentation Fault".
The program runs great on small data set, but when I run it on a super-large graph (more than 800,000 nodes), it says "Segmentation Fault".
這可能是什么原因?謝謝!
What might be the cause of it? Thank you!
附加信息:首先我在超大數據集上運行時遇到了這個錯誤:
Additional Info: First I got this Error when running on the super-large data set:
"RuntimeError: maximum recursion depth exceeded in cmp"
然后我使用重置遞歸限制
Then I reset the recursion limit using
sys.setrecursionlimit(50000)
但出現分段錯誤"
相信我,這不是一個無限循環,它在相對較小的數據上運行正確.可能是程序耗盡了資源?
Believe me it's not a infinite loop, it runs correct on relatively smaller data. It is possible the program exhausted the resources?
推薦答案
當 python extension(用 C 編寫)試圖訪問無法訪問的內存時會發生這種情況.
This happens when a python extension (written in C) tries to access a memory beyond reach.
您可以通過以下方式對其進行跟蹤.
You can trace it in following ways.
- 添加
sys.settrace
在代碼的第一行. 使用 Mark 在 this answer<中描述的
gdb
/a>.. 在命令提示符下
- Add
sys.settrace
at the very first line of the code. Use
gdb
as described by Mark in this answer.. At the command prompt
gdb python
(gdb) run /path/to/script.py
## wait for segfault ##
(gdb) backtrace
## stack trace of the c code
這篇關于是什么導致 Python 分段錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!