我有一个调用PyEnchant的多线程Python应用程序。我不是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分钟。在这些运行期间,它会处理数百个字符串并找到数百个未知单词。代码运行的机器没有已知的问题,它是我的开发机器,其他一切运行稳定。
任何人都可以了解这些错误的含义吗?我的Python代码中应该或不应该做些什么来解决它?我想这是一个内存问题(我知之甚少),我应该检查内存泄漏等吗?
答案 0 :(得分:2)
我做了一些测试,发现它适用于单个工作线程。经过一段时间的谷歌搜索后,我发现http://aspell.net/在“需要完成的事情”下说了“使Aspell Thread安全。即使Aspell本身不是多线程的,我希望它是线程安全的,以便它可以被多线程程序使用。”我通过附魔使用Aspell与PyEnchant,所以我猜我所看到的可以预期。 我联系了Enchant http://www.abisource.com/projects/enchant/的作者,他们说“附魔本身就是线程安全。不幸的是,它的一些后端可能不是,就像你在Aspell找到的那样。这是我们可以在附魔中解决的问题但是,通过序列化对Aspell字典的所有访问,从而将线程不安全隐藏到用户。“我可以提交增强请求吗?所以我已经提交了一份增强请求,并期待在适当的时候进行增强。