Skip to content

Cannot use Process.detach #246

@kidlab

Description

@kidlab

I am not sure this is an issue or there is something wrong in my following code:

# To mimic the Process.fork in MRI Ruby
module JRubyProcess
  require 'ffi'
  extend FFI::Library
  ffi_lib FFI::Library::LIBC
  attach_function :fork, [], :int
end

def transfer
  internal_server = self.init_server
  pid = JRubyProcess.fork do
    internal_server.run
  end

  # Make the server process run indepently.
  Process.detach(pid)

  internal_client = self.init_client
  # Do other stuff with connecting to internal_server...
  internal_client.post('some data')    
ensure
  # Kill server
  Process.kill('KILL', pid) if pid
end

My tending is to run the internal server in another Ruby interpreter then I can kill the server process.
The 'transfer' method worked well in MRI Ruby. In JRuby, however, it will raise an exception when it runs to 'Process.detach(pid)':

Java::JavaLang::RuntimeException: CallBlock does not have a static scope; this should not be called
    from org.jruby.runtime.CallBlock.getStaticScope(CallBlock.java:107)
    from org.jruby.RubyProc.setup(RubyProc.java:159)
    from org.jruby.RubyProc.newProc(RubyProc.java:118)
    from org.jruby.RubyProc.newProc(RubyProc.java:113)
    from org.jruby.Ruby.newProc(Ruby.java:2936)
    from org.jruby.internal.runtime.RubyRunnable.<init>(RubyRunnable.java:60)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions