Search code examples
pythonjrubynltkrubypython

Rubypython error during importing NLTK


I have problem with command "import nltk" in my jRuby/Rails project. The interesting thing is, that everything works well if I run the code with "import nltk" on webrick server for first time after restart webrick. Any other attempt to run code finishes with error shown below. Any idea why this is happening? My Python is 2.7, jRuby 1.6.7.

In jruby code I call simply:

RubyPython.start # start the Python interpreter

nltk = RubyPython.import("nltk")

RubyPython.stop # stop the Python interpreter

After second call of above code then error:

#
# 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
.......

Solution

  • Looks like rubypython does its magic with FFI. If there is a problem with FFI binary (which comes with JRuby) and/or JVM you're using, there is not much you can do when JVM segfaults.

    Try a newer JRuby version and/or JVM, but beyond that, I am afraid you are not going to get much help here.

    To wit, it works on my 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."