Message6784
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
else:
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:59 | ph4r05 | set | messageid: <1330186079.7.0.615003654234.issue1313@psf.upfronthosting.co.za> |
2012-02-25 16:07:59 | ph4r05 | set | recipients:
+ ph4r05, fwierzbicki, draghuram, pekka.klarck, pjenvey, doublep, marc, joey@cadence.com |
2012-02-25 16:07:59 | ph4r05 | link | issue1313 messages |
2012-02-25 16:07:58 | ph4r05 | create | |
|