Hi, I''m still searching for a way to halt or interrupt the execution of an IronRuby script. At the moment I do it by executing each script on a separate thread and call Thread.Abort but that is resulting in a memory and thread leak in my server application. As things have got busier on the server the leak has reduced the time the server can stay up from days to half a day or less. I came across the DLR hosting document on CodePlex http://dlr.codeplex.com/Wiki/View.aspx?title=Docs%20and%20specs and was wondering if there is anything in the IronRuby pipeline regarding "Interrupt Execution" (chapter 3.4 page 27 of the spec)? It''s exactly what I''m after and also describes the exact issue I''m encountering with the rude thread aborts. I''ve quoted the relevant text below for interested parties. Other than that is it possible to execute an IronRuby script line by line? I have been able to execute individual expressions but as soon as I try something like a multi-line expression like a case statement I haven''t been able to find a way. "Interrupt Execution: Language supports DLR mechanisms for host to abort execution cleanly so that host can interrupt runaway code. If we allow languages to avoid this work, then those langs cannot be used in the host''s process, cannot support in-situ REPLs for interactive development, etc. If the language uses DLR compilation or interpretation, they should not need to do anything. This is important because if the host has to stop execution by calling Thread.Abort or other rude abort, the thread could have transitioned into an unsafe portion of the host''s code. This could happen via the script code calling back on the host OM which in turn calls an internal API not coded for rude aborts." Thanks, Aaron Clauson -- Posted via http://www.ruby-forum.com/.
After spending a few hours delving into the DLR source I suspect the "interrupt execution" implementation is more related to the DLR core than IronRuby so I''ve posted a question over there http://dlr.codeplex.com/Thread/View.aspx?ThreadId=62052. Regards, Aaron -- Posted via http://www.ruby-forum.com/.
There is currently no support for execution interruption in DLR or IronRuby. It is not sufficient to insert termination checks in DLR interpreter. You need to add checks on other places too. And it''s better not to do it in the interpreter because interpreted code gets compiled after a while (or even immediately if it contains loops) and then your checks are gone. It is also not sufficient to look for loops in DLR trees produced by IronRuby (e.g. "loop" method performs the looping inside C# code). The easiest way how to make this work is to place check into - WhileLoopExpression.cs: inside the infinite loop (AstFactory.Infinite...) - this ensures that all while loops in Ruby code are can be interrupted. - BlockDefinition.cs: right after Ast.Label(redoLabel). This makes any block-based loops interruptible. This should allow you to interrupt any Ruby loop. Note that interrupting Ruby code can corrupt the state of the VM (ScriptRuntime) so you should probably not reuse that Runtime for other executions. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Aaron Clauson Sent: Thursday, July 09, 2009 4:44 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Interrupt Execution After spending a few hours delving into the DLR source I suspect the "interrupt execution" implementation is more related to the DLR core than IronRuby so I''ve posted a question over there http://dlr.codeplex.com/Thread/View.aspx?ThreadId=62052. Regards, Aaron -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core