This project has moved and is read-only. For the latest updates, please go here.

Is it possible to interrupt a running script?

Jun 28, 2012 at 1:00 PM

Hi, is there a way to interrupt a running script? I have 2 situations right now where this would be useful:

  • Dealing with throttling a long running script I do not have control of - Ideally I would be able to pause the script, yield the thread and then resume the script. I suspect that this is not possible but I'll ask just in case.
  • In a situation in which a script is looping infinitely  I need a way to terminate it. So far in testing just deleting the engine does not stop the script and I'm not sure where to go from there... I tried aborting the thread but it just seems to block.

Thanks for your help and this awesome library,


Jun 28, 2012 at 1:34 PM

As I found out at some point (writing automated tests for jurassic); No it is not.

Even throwing interrupts does not guarantee you that it will stop.

I resolved the issue by creating a separate process that ran my test, and if it took too long, I simply killed it.

Jun 28, 2012 at 2:22 PM
Edited Jun 28, 2012 at 4:43 PM

Thanks for the response Alxandr, although it's not really what I wanted to hear... I sometimes have up to 30 engines running at one time so separate processes for each would probably be horrible... I have managed to stop the threads using Thread.Suspend() but that is a deprecated method still doesn't technically stop the engine - just pauses it indefinitely. I don't know much about how Jurassic actually works in terms of the compiling and stuff, do you think it might be possible for me to edit the compiling it is such a way that it is possible to terminate the script? Add some kind of check to the compiled code or something...?



Jun 29, 2012 at 2:32 AM

I'm not aware of any problem with using Thread.Abort()... is that what you meant by "throwing interrupts" Alxandr?

Jun 29, 2012 at 7:56 AM

Yeah, exactly.

In some rare cases (with infinite loops I think), interrupts never reach the thread as far as I figured.

Though, in general, you shouldn't be doing infinite loops anyways...

Jun 30, 2012 at 9:58 AM

Hmm that's weird, I could have sworn that I read somewhere that you could always abort a thread, provided the thread was executing managed code (i.e. not in the middle of calling an native method).  Of course, large parts of .NET call into native code but the abort should always happen when execution returns from the native method.