BLOG
Enjoy when you can, and endure when you must.
JUL 31, 2014/Python
Segmentation Fault: 11

今天同事在Mac上使用Python遇到一个问题,在Terminal中运行Python,执行第二条语句时就会提示Segmentation Fault: 11,然后直接崩溃。

发生问题的Python版本是2.7.5,这在之前确实没有遇到过,于是Google一下,发现这是一个bug引起的。以下是该问题的描述(来自http://bugs.python.org/issue18458):

Modules/readline.c contains a workaround for a bug in the readline emulation of libedit: that emulation uses a different starting offset for the history than the real readline.

那么其中一种解决方法就是禁用readline,切换至目录:

/Library/Frameworks/Python.framework/Versions/[x.x]/lib/python3.3/lib-dynload

其中的x.x代表Python版本,如2.7。

然后将readline.so改名即可,如:

mv readline.so readline.so.disabled

还有一种方法就是直接升级Python版本,如2.7.6,该版本解决了这个bug。

参考资料

[stackoverflow]Python crashing when running two commands (Segmentation Fault: 11)

[Python bug tracker]Issue18458:interactive interpreter crashes and test_readline

COMMENTS
LEAVE COMMNT