Hello,
I’ve found various other posts suggesting that CTRL-C is handled by the
JVM
… I’m trying to figure out what the current status is.
In a trivial script (trap + while true) it appears to be handled fine,
but
when using java objects my script is aborted halfway through the trap
block
(perhaps when it calls back into java land?):
Whatever the intended behaviour, I would expect it to be “nicer” than
this
experience - either raising when I attempt to trap the signal, or
running
the entire block, not just half of it.
On Tue, Sep 6, 2011 at 11:23 AM, Charles Oliver N. [email protected]wrote:
Hmm, that should work ok. Can you come up with an example that doesn’t
use Neo4j and shows the same problem? I’d like to try to reproduce.
I have just tried and was unable. My script should work with only a gem install neo4j, it’s all in-process and doesn’t require an external
install
of neo4j (I don’t think).
FWIW, IRB, RSpec, and others hook SIGINT in JRuby and work fine (as
far as I know).
The only difference I can see is that these don’t call back into java
objects in the trap, but then just using simple java apis
(System.currentTimeInMillis, for instance) I couldn’t reproduce.
Seems the sleep 1 call in the SIGINT handler is confounding
JRuby…removing it works as expected. Not apples-to-apples, but I
don’t understand why the presence of the SIGINT handler sleep seems to
impact JRuby.
C:\Users\Jon\Documents\RubyDev\sandbox>jruby -v trap_sigint.rb
jruby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768) (Java HotSpot™
Client VM 1.7.0) [Windows 7-x86-java]
started
Spewing 0.358074204524305
Did something
Spewing 0.282736311044042
Did something
Spewing 0.682749884231586
Did something
Spewing 0.0601113988185775
1
Did something
C:\Users\Jon\Documents\RubyDev\sandbox>ruby -v trap_sigint.rb
ruby 1.9.3dev (2011-09-04 revision 33179) [i386-mingw32]
started
Spewing 0.45458906220783335
Did something
Spewing 0.017654727547826266
Did something
Spewing 0.632952442589301
Did something
Spewing 0.06243992225919326
1
2
Seems the sleep 1 call in the SIGINT handler is confounding JRuby…removing
it works as expected. Not apples-to-apples, but I don’t understand why the
presence of the SIGINT handler sleep seems to impact JRuby.
It’s possible that thread effects are killing the signal handler, in
order to keep the signal-handling thread in the JVM working as
prescribed. Time to open a bug and we can try to investigate.
A possible workaround might be to register a SIGINT handler that does
nothing but tells JRuby to exit (Kernel#exit), with your shutdown
logic in an at_exit hook. Can someone try that?