From: Luc Heinrich Date: 2006-01-17T09:30:11+09:00 Subject: Re: Resetting ruby On 16 janv. 06, at 12:33, Dalibor Sramek wrote: > The possibility to reset the interpreter would be IMHO useful also > for other > situations where you have persistent Ruby processes (think mod_ruby). (going slightly offtopic) I have recently dived into Tcl (the "Practical Programming in Tcl and Tk" book by Welch, Jones and Hobbs is pretty good) and while I still haven't managed to go past the "o-m-f-g-YUCK!" state as far as the core language is concerned, I must say that the core implementation provides some *really* nifty features which I would *really* love to see in Ruby and which would incidentally make the original poster question trivial to do. For example, you can spawn clean and fresh "sub-interpreter(s)" which you can then use as isolated (and optionally safe) sandboxe(s). Here's a sample usage: % interp create worker worker % interp eval worker {set a 42} 42 % puts $a can't read "a": no such variable % interp delete worker In the first line we create a sub-interpreter and name it 'worker'. In the second line we execute a simple command: we set assign the value 42 to the variable 'a'. In the third line we try to print the value of 'a', which causes an error. This shows that the 'main' interpreter and our 'worker' sub-interpreter are clearly isolated from each other. Finally, we get rid of the sub-interpreter. Another (different) aspect of Tcl which I really like is how event loops are used to provide ultra-simple interthreads communication with message queuing and all that jazz: % package require Thread % set worker [thread::create] % thread::send -async $worker {...some longish calculation...} % thread::send -async $worker {...some other longish calculation...} % ...continue on the main thread... Rite is supposed to be reentrant, so I guess that it shouldn't be very hard to build such things upon Ruby 2.0. Oh my, I am *so* looking forward to it... :) -- Luc Heinrich - luc@honk-honk.com - http://www.honk-honk.com