From: Timothy Mann <mann23@po...> - 2007-01-10 16:33:59
I am currently using Jython as an embedded script interpreter which
executes scripts in independent threads. I would like to have a Java
method in the main thread be able to pause the progress of currently
running Jython scripts without requiring any additional coding in the
scripts themselves. I have three ways that I might approach this problem.
First and simplest, I could include checks in Java methods that are called
by scripts which would pause the application is paused and one of the
methods with this check is called. The main problem with this is that it
is not reliable. Not all scripts will necessarily call one of these
special methods and therefore may not yield. For example, imagine a while
loop that calls a built-in function. This code would continue until the
while loop is broken(which may be never).
Second, I could alter the actual Jython interpreter code to execute and
then check for paused conditions. I think that this might be a better
solution, but I would rather not have to wade through tons of code. I'm
worried that the compilation process makes this type of modification
Last, the application could add function calls to the code before it is
compiled. It would call application.waitUntilNotPaused() between each
I would be glad to hear any advice on the matter. It may be worth while to
investigate the second option if this is a feature others are interested
Thank you for your help.
From: Petr Gladkikh <petrglad@gm...> - 2007-01-11 07:37:58
On 1/10/07, Timothy Mann <mann23@...> wrote:
> Last, the application could add function calls to the code before it is
> compiled. It would call application.waitUntilNotPaused() between each
IMO this would be best approach (you probably wanted to say
thread.waitWhilePaused()?). However to pause application at arbitrary
JVM instuctions you could use either JVM emulator (that's complex and
I am not aware of Java emulators written in java - so this is not
practical) or java debugger (that presumably would slow your entire
application). Forcibly blocking a thread at random points is
deadlock-prone so it is not safe - even if you do not use locks they
may occur in underlying Java code.
However it is worth asking if Jython has some kind of Python
interpreter at jython-dev@... If it has - it would
be not so hard to install some hooks there and use interpreted Jython
code only (although Jython scripts will run slowly in this case).
I hope this helps.