Python PyEnchant 分段错误或指针无效



我有一个多线程的Python应用程序,它调用PyEnchant。我不是Python专家,大部分代码来自第三方。我所做的是添加代码以从多线程应用程序调用 PyEnchant。由于我进行了更改,因此应用程序运行的时间长短不一,然后崩溃。我在 Ubuntu 12.04 上运行它。我收到如下错误:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc5ffd700 (LWP 6858)]
0x00007ffff4424854 in ?? () from /usr/lib/libenchant.so.1
(gdb) backtrace
#0  0x00007ffff4424854 in ?? () from /usr/lib/libenchant.so.1
#1  0x00007ffff442517d in enchant_dict_check () from /usr/lib/libenchant.so.1
#2  0x00007ffff48a2ea4 in ffi_call_unix64 () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#3  0x00007ffff48a28c5 in ffi_call () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#4  0x00007ffff48932c2 in _ctypes_callproc () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#5  0x00007ffff4893aa2 in ?? () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#6  0x00000000004c7c76 in PyObject_Call ()
#7  0x000000000042aa4a in PyEval_EvalFrameEx ()
#8  0x000000000042abe2 in PyEval_EvalFrameEx ()
#9  0x000000000042abe2 in PyEval_EvalFrameEx ()
#10 0x00000000004317f2 in PyEval_EvalCodeEx ()
#11 0x000000000054aa40 in ?? ()
#12 0x00000000004c7c76 in PyObject_Call ()
#13 0x000000000049e9ba in ?? ()
#14 0x00000000004c7c76 in PyObject_Call ()
#15 0x00000000004c7d36 in PyEval_CallObjectWithKeywords ()
#16 0x0000000000443e3a in ?? ()
#17 0x000000000042a862 in PyEval_EvalFrameEx ()
#18 0x000000000042abe2 in PyEval_EvalFrameEx ()
#19 0x000000000042abe2 in PyEval_EvalFrameEx ()

*** glibc detected *** /usr/bin/python: free(): invalid pointer: 0x00007fffd4000178 ***
(gdb) backtrace
#0  0x00007ffff68fa445 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff68fdbab in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff6937e2e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00007ffff6942626 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4  0x00007ffff4424861 in ?? () from /usr/lib/libenchant.so.1
#5  0x00007ffff442517d in enchant_dict_check () from /usr/lib/libenchant.so.1
#6  0x00007ffff48a2ea4 in ffi_call_unix64 () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#7  0x00007ffff48a28c5 in ffi_call () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#8  0x00007ffff48932c2 in _ctypes_callproc () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#9  0x00007ffff4893aa2 in ?? () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#10 0x00000000004c7c76 in PyObject_Call ()
#11 0x000000000042aa4a in PyEval_EvalFrameEx ()
#12 0x000000000042abe2 in PyEval_EvalFrameEx ()
#13 0x000000000042abe2 in PyEval_EvalFrameEx ()
#14 0x00000000004317f2 in PyEval_EvalCodeEx ()
#15 0x000000000054aa40 in ?? ()
#16 0x00000000004c7c76 in PyObject_Call ()
#17 0x000000000049e9ba in ?? ()
#18 0x00000000004c7c76 in PyObject_Call ()
#19 0x00000000004c7d36 in PyEval_CallObjectWithKeywords ()
#20 0x0000000000443e3a in ?? ()
#21 0x000000000042a862 in PyEval_EvalFrameEx ()
#22 0x000000000042abe2 in PyEval_EvalFrameEx ()

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe57fa700 (LWP 17532)]
0x0000000000000000 in ?? ()
(gdb) backtrace
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff3f5fe33 in g_hash_table_lookup () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x00007ffff44245a3 in ?? () from /usr/lib/libenchant.so.1
#3  0x00007ffff442518b in enchant_dict_check () from /usr/lib/libenchant.so.1
#4  0x00007ffff48a2ea4 in ffi_call_unix64 () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#5  0x00007ffff48a28c5 in ffi_call () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#6  0x00007ffff48932c2 in _ctypes_callproc () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#7  0x00007ffff4893aa2 in ?? () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#8  0x00000000004c7c76 in PyObject_Call ()
#9  0x000000000042aa4a in PyEval_EvalFrameEx ()
#10 0x000000000042abe2 in PyEval_EvalFrameEx ()
#11 0x000000000042abe2 in PyEval_EvalFrameEx ()
#12 0x00000000004317f2 in PyEval_EvalCodeEx ()
#13 0x000000000054aa40 in ?? ()
#14 0x00000000004c7c76 in PyObject_Call ()
#15 0x000000000049e9ba in ?? ()
#16 0x00000000004c7c76 in PyObject_Call ()
#17 0x00000000004c7d36 in PyEval_CallObjectWithKeywords ()
#18 0x0000000000443e3a in ?? ()
#19 0x000000000042a862 in PyEval_EvalFrameEx ()
#20 0x000000000042abe2 in PyEval_EvalFrameEx ()
#21 0x000000000042abe2 in PyEval_EvalFrameEx ()
#22 0x000000000042abe2 in PyEval_EvalFrameEx ()

阅读我尝试过的另一篇帖子

ulimit -s unlimited

以及 ulimit 的各种其他值,但它似乎没有帮助。

我已经监视了使用"top"运行的应用程序,它似乎没有使用太多资源。有时它运行 5 分钟,有时运行 15 分钟。在这些运行过程中,它会处理数百个字符串并找到数百个未知单词。运行代码的机器没有已知问题,这是我的开发机器,其他一切都稳定运行。

任何人都可以阐明这些错误的含义吗?在我的 Python 代码中,我应该或不应该做一些事情来解决这个问题吗?我想这是一个内存问题(我对此知之甚少),我应该检查内存泄漏等吗?

我做了更多的测试,发现它适用于单个工作线程。经过一番谷歌搜索,我发现 http://aspell.net/在"需要做的事情"下说;"让阿咒线程安全。即使Aspell本身不是多线程的,我也希望它是线程安全的,以便多线程程序可以使用它。我正在通过Enchant将Aspell与PyEnchant一起使用,所以我想我所看到的是可以预期的。我联系了Enchant的作者 http://www.abisource.com/projects/enchant/他们说"Enchant本身是线程安全的。不幸的是,它的一些后端可能不是,例如您在 Aspell 中发现的那样。不过,我们可以在 Enchant 中解决这个问题,通过序列化对 Aspell 字典的所有访问,从而隐藏对用户的线程不安全。 我可以提交增强请求吗?因此,我已提出增强请求,并期待在适当的时候进行增强。

相关内容

  • 没有找到相关文章

最新更新