Python:help(numpy)导致退出时出现segfault

时间:2013-06-27 13:48:29

标签: python ubuntu python-2.7 numpy segmentation-fault

我遇到了一个奇怪的事情:在python解释器中,我执行以下操作:

>>>import numpy
>>>help(numpy)

帮助显示正确,但只要按q返回解释器:

Segmentation fault (core dumped)

我不知道是什么导致了段错误,如果我用本地名称(典型的np)导入numpy,它仍然会发生。任何其他库都不会发生这种情况。我尝试卸载并重新安装numpy,但这没有任何区别。 numpy是否太大而无法处理,或者我的翻译有问题?我该如何解决这个问题?

我正在运行Ubuntu 13.04 32位并使用Python 2.7.4。

更新: PYTHONSTARTUP和PYTHONPATH都是空的。 编写执行此操作的脚本具有完全相同的效果。

此外,numpy和其他库工作得很好,这只是在numpy上使用时出现的帮助调用。

更新2:

对于test.py:

if __name__ == "__main__":
    import numpy
    help(numpy)

这是gdb输出:

$ gdb --args python test.py
GNU gdb (GDB) 7.5.91.20130417-cvs-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python2.7...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/python2.7 test.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

Program received signal SIGPIPE, Broken pipe.
0xb7fdd424 in __kernel_vsyscall ()
(gdb) where
#0  0xb7fdd424 in __kernel_vsyscall ()
#1  0xb7eb2cf3 in write () from /lib/i386-linux-gnu/libc.so.6
#2  0xb7e447e1 in _IO_file_write () from /lib/i386-linux-gnu/libc.so.6
#3  0xb7e446c6 in ?? () from /lib/i386-linux-gnu/libc.so.6
#4  0xb7e45422 in _IO_file_xsputn () from /lib/i386-linux-gnu/libc.so.6
#5  0xb7e3a025 in fwrite () from /lib/i386-linux-gnu/libc.so.6
#6  0x080ac05b in ?? ()
#7  0x080b6bde in PyEval_EvalFrameEx ()
#8  0x080b71c0 in PyEval_EvalFrameEx ()
#9  0x0811f939 in PyEval_EvalCodeEx ()
#10 0x080b80d4 in PyEval_EvalFrameEx ()
#11 0x080b71c0 in PyEval_EvalFrameEx ()
#12 0x0811f939 in PyEval_EvalCodeEx ()
#13 0x080b7265 in PyEval_EvalFrameEx ()
#14 0x080b71c0 in PyEval_EvalFrameEx ()
#15 0x0811f939 in PyEval_EvalCodeEx ()
#16 0x081203ee in ?? ()
#17 0x080e11f9 in ?? ()
#18 0x080e3daf in PyObject_Call ()
#19 0x08129483 in ?? ()
#20 0x080b8a3e in PyEval_EvalFrameEx ()
#21 0x0811f939 in PyEval_EvalCodeEx ()
#22 0x0812029e in ?? ()
---Type <return> to continue, or q <return> to quit---
#23 0x080e11f9 in ?? ()
#24 0x080e3daf in PyObject_Call ()
#25 0x0816dd88 in ?? ()
#26 0x080b7615 in PyEval_EvalFrameEx ()
#27 0x0811f939 in PyEval_EvalCodeEx ()
#28 0x081836c7 in PyEval_EvalCode ()
#29 0x08183b7d in ?? ()
#30 0x080a6032 in PyRun_FileExFlags ()
#31 0x080a65f8 in PyRun_SimpleFileExFlags ()
#32 0x080a74af in Py_Main ()
#33 0x080a7581 in main ()
(gdb) 

更新3:

$strace -f python test.py的输出很长,这是克隆子进程的最后几行:

[pid  2610] clone(Process 2611 attached child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7527968) = 2611
[pid  2610] wait4(-1, Process 2610 suspended
<unfinished ...>
[pid  2611] execve("/usr/bin/less", ["less"], [/* 53 vars */]) = 0
[pid  2611] brk(0)                      = 0x89ed000
[pid  2611] access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
[pid  2611] mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7734000
[pid  2611] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[pid  2611] open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[pid  2611] fstat64(3, {st_mode=S_IFREG|0644, st_size=93821, ...}) = 0
[pid  2611] mmap2(NULL, 93821, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb771d000
[pid  2611] close(3)                    = 0
[pid  2611] access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
[pid  2611] open("/lib/i386-linux-gnu/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = 3
[pid  2611] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320W\0\0004\0\0\0"..., 512) = 512
[pid  2611] fstat64(3, {st_mode=S_IFREG|0644, st_size=121032, ...}) = 0
[pid  2611] mmap2(NULL, 124748, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb76fe000
[pid  2611] mmap2(0xb771a000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b) = 0xb771a000
[pid  2611] close(3)                    = 0
[pid  2611] access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
[pid  2611] open("/lib/i386-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
[pid  2611] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\220\232\1\0004\0\0\0"..., 512) = 512
[pid  2611] fstat64(3, {st_mode=S_IFREG|0755, st_size=1770984, ...}) = 0
[pid  2611] mmap2(NULL, 1780508, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb754b000
[pid  2611] mmap2(0xb76f8000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ad) = 0xb76f8000
[pid  2611] mmap2(0xb76fb000, 11036, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb76fb000
[pid  2611] close(3)                    = 0
[pid  2611] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb754a000
[pid  2611] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7549000
[pid  2611] set_thread_area({entry_number:-1 -> 6, base_addr:0xb75496c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
[pid  2611] mprotect(0xb76f8000, 8192, PROT_READ) = 0
[pid  2611] mprotect(0xb771a000, 8192, PROT_READ) = 0
[pid  2611] mprotect(0x8069000, 4096, PROT_READ) = 0
[pid  2611] mprotect(0xb7757000, 4096, PROT_READ) = 0
[pid  2611] munmap(0xb771d000, 93821)   = 0
[pid  2611] ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] brk(0)                      = 0x89ed000
[pid  2611] brk(0x8a0e000)              = 0x8a0e000
[pid  2611] stat64("/home/marzul/.terminfo", 0xbfac7780) = -1 ENOENT (No such file or directory)
[pid  2611] stat64("/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
[pid  2611] access("/etc/terminfo/x/xterm", R_OK) = -1 ENOENT (No such file or directory)
[pid  2611] stat64("/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
[pid  2611] access("/lib/terminfo/x/xterm", R_OK) = 0
[pid  2611] open("/lib/terminfo/x/xterm", O_RDONLY|O_LARGEFILE) = 3
[pid  2611] fstat64(3, {st_mode=S_IFREG|0644, st_size=3315, ...}) = 0
[pid  2611] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7733000
[pid  2611] read(3, "\32\1)\0&\0\17\0\235\1Z\5xterm|xterm-debian|X"..., 4096) = 3315
[pid  2611] read(3, "", 4096)           = 0
[pid  2611] close(3)                    = 0
[pid  2611] munmap(0xb7733000, 4096)    = 0
[pid  2611] ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] ioctl(1, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
[pid  2611] ioctl(2, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
[pid  2611] open("/usr/bin/.sysless", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
[pid  2611] open("/etc/sysless", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
[pid  2611] open("/home/marzul/.less", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
[pid  2611] open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
[pid  2611] fstat64(3, {st_mode=S_IFREG|0644, st_size=8748544, ...}) = 0
[pid  2611] mmap2(NULL, 2097152, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7349000
[pid  2611] mmap2(NULL, 4096, PROT_READ, MAP_PRIVATE, 3, 0x5e1) = 0xb7733000
[pid  2611] close(3)                    = 0
[pid  2611] open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
[pid  2611] fstat64(3, {st_mode=S_IFREG|0644, st_size=8748544, ...}) = 0
[pid  2611] mmap2(NULL, 4096, PROT_READ, MAP_PRIVATE, 3, 0x5d8) = 0xb7732000
[pid  2611] close(3)                    = 0
[pid  2611] open("/home/marzul/.lesshst", O_RDONLY|O_LARGEFILE) = 3
[pid  2611] fstat64(3, {st_mode=S_IFREG|0600, st_size=129, ...}) = 0
[pid  2611] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =     0xb7731000
[pid  2611] read(3, ".less-history-file:\n.search\n\"pus"..., 4096) = 129
[pid  2611] read(3, "", 4096)           = 0
[pid  2611] close(3)                    = 0
[pid  2611] munmap(0xb7731000, 4096)    = 0
[pid  2611] open("/dev/tty", O_RDONLY|O_LARGEFILE) = 3
[pid  2611] ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] fsync(3)                    = -1 EINVAL (Invalid argument)
[pid  2611] ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] ioctl(3, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig -icanon -echo ...}) = 0
[pid  2611] ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
[pid  2611] rt_sigaction(SIGINT, {0x805cc00, [INT], SA_RESTART}, {SIG_DFL, [], 0}, 8) = 0
[pid  2611] rt_sigaction(SIGTSTP, {0x805cb80, [TSTP], SA_RESTART}, {SIG_DFL, [], 0}, 8) = 0
[pid  2611] rt_sigaction(SIGWINCH, {0x805cbc0, [WINCH], SA_RESTART}, {SIG_DFL, [], 0}, 8) = 0
[pid  2611] rt_sigaction(SIGQUIT, {SIG_IGN, [QUIT], SA_RESTART}, {SIG_DFL, [], 0}, 8) = 0
[pid  2611] ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfac9088) = -1 ENOTTY (Inappropriate ioctl for device)
[pid  2611] stat64("-", 0xbfac90a0)     = -1 ENOENT (No such file or directory)
[pid  2611] write(1, "\33[?1049h\33[?1h\33=\r", 16) = 19
[pid  2611] fsync(3)                    = -1 EINVAL (Invalid argument)
[pid  2611] ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
[pid  2611] ioctl(3, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
[pid  2611] exit_group(0)               = ?
Process 2610 resumed
Process 2611 detached
[pid  2610] <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 2611
[pid  2610] --- SIGCHLD (Child exited) @ 0 (0) ---
[pid  2610] sigreturn()                 = ? (mask now [])
[pid  2610] exit_group(0)               = ?
Process 2610 detached
<... write resumed> )                   = 73728
--- SIGPIPE (Broken pipe) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
write(4, "l the attributes of the ndarray "..., 3043328) = -1 EPIPE (Broken pipe)
--- SIGPIPE (Broken pipe) @ 0 (0) ---
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV (core dumped) +++
Segmentation fault (core dumped)

更新4:

$echo $LESS

$cat cat ~/.less
cat: /home/user/.less: No such file or directory

显然根本没有配置。

在“= 4”的终端搜索没有被截断的内容,给出了以下几个部分:

read(3, "---------\n    a, b : ndarray\n\n  "..., 4096) = 4096
read(3, "epstr = \", \"\n    arglist = argum"..., 4096) = 4096
read(3, "* Total of %d references found. "..., 4096) = 4096
read(3, "`output` not supplied then sourc"..., 4096) = 4096
read(3, "      r += sum([200 for w in wha"..., 4096) = 4096
read(3, "                  except NameErr"..., 4096) = 4096
read(3, "          return tuple([self.vis"..., 4096) = 4018

[pid  3294] write(2, "Missing filename (\"less --help\" "..., 42) = 42

更新5:

$strace -f python test.py 2>&1 | tee -a out.txt ; (exit ${PIPESTATUS})
$cat out.txt | grep "open(.*) = 4"

open("/usr/lib/python2.7/site.pyc", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/os.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/traceback.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/sysconfig.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/re.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/_sysconfigdata.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/local/lib/python2.7/dist-packages/easy-install.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/PILcompat.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/gtk-2.0-pysupport-compat.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/pygtk.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/python-support.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/setuptools.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/ubuntu-sso-client.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/ubuntuone-client.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/ubuntuone-control-panel.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/wx.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/zope.interface-4.0.5-nspkg.pth", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/sitecustomize.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/encodings/__init__.pyc", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/codecs.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/encodings/aliases.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/encodings/utf_8.pyc", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/__init__.pyc", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/__config__.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/version.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/_import_tools.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/fft/__init__.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/polynomial/__init__.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/random/__init__.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/ctypeslib.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/dist-packages/numpy/ma/__init__.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/inspect.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/pkgutil.py", O_RDONLY|O_LARGEFILE) = 4
open("/usr/lib/python2.7/repr.py", O_RDONLY|O_LARGEFILE) = 4

更新6:

没有open(...)我也找到了:

ERR_PRINT = 4
FPE_UNDERFLOW = 4

1 个答案:

答案 0 :(得分:5)

从Python方面,我设法在pydoc.py ...

中跟踪这个功能
def pipepager(text, cmd):
    """Page through text by feeding it to another program."""
    pipe = os.popen(cmd, 'w')
    try:
        pipe.write(text)
        pipe.close()
    except IOError:
        pass # Ignore broken pipes caused by quitting the pager program.

...特别是pipe.write(text)行。

如果将该功能更改为...

,问题就会消失
def pipepager(text, cmd):
    """Page through text by feeding it to another program."""
    import subprocess
    pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True).stdin
    try:
        pipe.write(text)
        pipe.close()
    except IOError:
        pass # Ignore broken pipes caused by quitting the pager program.

......这可能是一个合理的解决方法,虽然我仍在调查解决问题的原因 - 两种情况的strace(1)输出之间差别很小。


<强>更新

Leeward已为此提出a bug report