Using the thread status handler is not good solution for me, because in that case I can not stop interpreter then some I/O actions performs. Also I can not insert code to the original scipt because that script is external to me.
From: Ype Kingma <ype@...>
To: "Алексей Долгов" <walldog@...
Date: Tue, 3 Dec 2002 23:27:09 +0100
Subject: Re: [Jython-users] How to stop Jython interpreter
> On Tuesday 03 December 2002 22:42, Алексей Долгов wrote:
> > Hello!
> > I need help to figure out how I can stop or interrupt embedded Jython
> > interpreter. I use Jython interpreter in my program to execute Jython
> > scripts and need to stop it in any time. Does anyone know about it?
> It's as difficult as stopping a Java thread. The jython interpreter
> ignores the thread interrupted status, which would only slow it down.
> Since any java code can be called from jython, checking interrupted status
> would not guarantee anything anyway.
> You either have to check some status in your jython scripts (eg. thread
> interrupted status), or you'll have to use a deprecated method to
> stop the thread running the interpreter. An example of this
> can be found in Console.py in the swing demo directory of the
> jython installation. In case you use it, make sure you read the
> documentation of java.lang.Thread on this.
> I'd recommend to write a function eg. ExceptionOnCancel
> that throws an appropriate exception when cancelled (from
> another thread) and call this function as the first statement of
> each loop (since koops are portentially infinite) and/or
> just before or after any repeated call to (java) code that might
> take some time eg. due to I/O. Use try/finally to release anything
> that might need releasing.
> It's a bit of work, but it pays off, at least it did for me. A hanging
> thread can be difficult to debug and it's much nicer when all
> threads finish working when canceled.
> Have fun,