From: Branden Tanga Date: 2010-05-29T06:33:47+09:00 Subject: Re: Interrupting the evaluation of a ruby script Emmanuel Emmanuel wrote: > This is my problem : > > Let's say I have a ruby script which first takes as an input a ruby > script (that could be anything, and that I don't control) and evals it > using the eval ruby command and proceeds to some computations. > > Now the evaluation of the inputed script can take very long.... I would > like to be able to interrupt it (i.e., interrupt the eval command), > ideally from another ruby process, raising an exception that could be > trapped by my first process so the evaluation could be skipped and the > process could proceed to the other computations. > > I could send a SIGINT (in C) to the first process ? And trap this signal > in ruby in the first process... > I guess that should work (can I send it in ruby ? what os the command ?) > ? > > However, If I understand correctly, that will not work on Windows > platform.... > > What is the solution ? > > ANy idea ? > > Thank you > > Emmanuel Ruby noob here. I think what technique you would have to use would be determined by your requirements for stopping evaluation. If you need to "freeze" the eval, check some value, then carry on (or not), you can accomplish it within the same thread. If you need to have something like say, an independent timer which could send an interrupt to the eval, then you would need multi threading. If single threading is acceptable, couldn't you do something like the following? (forgive me for the horrible pseudocode) my_string = "some stuff here to evaluate" ... figure out where to insert a yield statement into my_string my_string.instance_eval do some_condition == true ? (throw error) : (carry on) end -- Posted via http://www.ruby-forum.com/.