导入NLTK时出现Rubypython错误

时间:2012-08-25 12:57:59

标签: python jruby nltk rubypython

我的jRuby / Rails项目中的命令“import nltk”有问题。有趣的是,如果我在webrick服务器上第一次运行带有“import nltk”的代码,那么一切都运行良好。任何其他运行代码的尝试都会完成,错误如下所示。知道为什么会这样吗?我的Python是2.7,jRuby 1.6.7。

在jruby代码中,我简单地称之为:

RubyPython.start # start the Python interpreter

nltk = RubyPython.import("nltk")

RubyPython.stop # stop the Python interpreter

在第二次调用上面的代码后,错误:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x89c9cc7a, pid=9774, tid=2319420224
#
# JRE version: 7.0_06-b24
# Java VM: Java HotSpot(TM) Server VM (23.2-b09 mixed mode linux-x86 )
# Problematic frame:
# C  [multiarray.so+0x78c7a]  _strided_zero_pad_data_copy+0x3106a
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x0a646400):  JavaThread "RubyThread-13: /usr/lib/jruby/lib/ruby/1.8/webrick/server.rb:162" daemon [_thread_in_native, id=9817, stack(0x8a1f8000,0x8a3f9000)]

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x00000001

Registers:
EAX=0x00000001, EBX=0x89d28ff4, ECX=0x00000001, EDX=0x8b879ad8
ESP=0x8a3c7d94, EBP=0x00000000, ESI=0x89d2c860, EDI=0x89d2c860
EIP=0x89c9cc7a, EFLAGS=0x00210202, CR2=0x00000001

Top of Stack: (sp=0x8a3c7d94)
0x8a3c7d94:   8b28f16c 8b2c78b8 89c303bd 89d28ff4
0x8a3c7da4:   89ddd21b 89d28ff4 89fb2680 89c7fa64
0x8a3c7db4:   89fb2680 89d2ba80 8b72aacc 89e536a4
0x8a3c7dc4:   89d28ff4 8bb85d54 8b879ad0 89cb601c
0x8a3c7dd4:   00000011 89d2bb60 8b829780 89e97d99
0x8a3c7de4:   00000007 8bb42840 8c54d71c 89d28ff4
0x8a3c7df4:   8b4f8c88 89d2c860 00000000 89cb80dc
0x8a3c7e04:   8b879ad8 89d2c860 00000004 00000000 

Instructions: (pc=0x89c9cc7a)
0x89c9cc5a:   89 04 24 e8 ae 25 f9 ff 85 c0 75 8a 83 c4 5c 5b
0x89c9cc6a:   5e 5f 5d c3 66 90 8b 54 24 70 8b 02 85 c0 74 ec
0x89c9cc7a:   83 00 01 83 c4 5c 5b 5e 5f 5d c3 8d 74 26 00 8d
0x89c9cc8a:   bc 27 00 00 00 00 53 83 ec 18 8b 54 24 20 e8 fa 

Register to memory mapping:

EAX=0x00000001 is an unknown value
EBX=0x89d28ff4: <offset 0x104ff4> in /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so at 0x89c24000
ECX=0x00000001 is an unknown value
EDX=0x8b879ad8 is an unknown value
ESP=0x8a3c7d94 is pointing into the stack for thread: 0x0a646400
EBP=0x00000000 is an unknown value
ESI=0x89d2c860: <offset 0x108860> in /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so at 0x89c24000
EDI=0x89d2c860: <offset 0x108860> in /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so at 0x89c24000


Stack: [0x8a1f8000,0x8a3f9000],  sp=0x8a3c7d94,  free space=1855k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [multiarray.so+0x78c7a]  _strided_zero_pad_data_copy+0x3106a

[error occurred during error reporting (printing native stack), id 0xb]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.kenai.jffi.Foreign.invokeArrayO1Int32(J[BLjava/lang/Object;III)I+0
.......

1 个答案:

答案 0 :(得分:0)

看起来rubypython在FFI中扮演着神奇的角色。如果你正在使用的FFI二进制文件(它附带JRuby)和/或JVM存在问题,那么在JVM段错误时你无能为力。

尝试更新的JRuby版本和/或JVM,但除此之外,我担心你不会在这里获得太多帮助。

即便如此,它适用于我的Mac。

$ cat test.rb               
require "rubypython"

RubyPython.start # start the Python interpreter

cPickle = RubyPython.import("cPickle")
p cPickle.dumps("Testing RubyPython.").rubify

RubyPython.stop # stop the Python interpreter
$ jruby -v; jruby -rubygems test.rb
jruby 1.7.0.preview2 (1.9.3p203) 2012-08-22 ff42564 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_04-b21 [darwin-x86_64]
"S'Testing RubyPython.'\np1\n."