Author ph4r05
Recipients doublep, draghuram, fwierzbicki,, marc, pekka.klarck, ph4r05, pjenvey
Date 2012-02-25.16:07:58
SpamBayes Score 1.29896e-14
Marked as misclassified No
Message-id <>
Hi everyone, 
i have worked on this problem several hours and now finally got solution.

I am using jython-2.5.3b1 library in my code. There should be attached my workaround code for this problem. It is complete Jython console, available to interrupt current code with SIGINT - worked for me 100%.

Short description of solution:
I use sighandler with few modifications as Marc suggested.
In sighandler I call to sys._jy_interpreter.interrupt(thp) where thp is ThreadState of main execution thread - here is need to differ between thread handling signals and main execution thread. Thus we need store ThreadState somewhere to reach it from different thread - sighandler.

Such call will cause Java Exception java.lang.Error and InteractiveConsole terminates. BUT when we start new InteractiveConsole, python state will remain same, thus environment objects will be still available as before SIGINT sending.

IMHO my workaround code could be easily adapted to fix this issue in jython, if needed. I leave this for others since I know Jython project only a few weeks.

Please consult attached workaround code. After start, it automatically registers own SIGINT handler. You can test it with this piece of code:
def fib( n ):
   if n == 0 or n == 1:
      return n
      return fib( n - 1 ) + fib( n - 2 )

Try running fib(10), this should work correctly. Next try to run fib(1000), this should freeze for a quite long time. Send SIGINT with CTRL-C. Code is interrupted and new instance of console is launched. Now you can verify that you can still call fib(5) correctly, as before freeze and console restart.

There is little problem with this solution - what if you really want to exit console? In this situation we can program not to start console again.

Hope this helps.
Date User Action Args
2012-02-25 16:07:59ph4r05setmessageid: <>
2012-02-25 16:07:59ph4r05setrecipients: + ph4r05, fwierzbicki, draghuram, pekka.klarck, pjenvey, doublep, marc,
2012-02-25 16:07:59ph4r05linkissue1313 messages
2012-02-25 16:07:58ph4r05create