[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Resetting ruby

List Recv

1/16/2006 1:29:00 AM

I'm looking for a fast way to "reset" Ruby. That is, to reset the
interpreter back to a fresh state, or, even better, a fresh state +
keeping some required ruby-gems.

My goal is to make a continuos test runner, and avoid the overhead of
having to restart ruby and require the gems each times.

I could do this with fork (copy-on-write), except I want this to run on
Win32 as well.

Any ideas?

--
Posted via http://www.ruby-....


17 Answers

Logan Capaldo

1/16/2006 1:41:00 AM

0


On Jan 15, 2006, at 8:29 PM, List Recv wrote:

> I'm looking for a fast way to "reset" Ruby. That is, to reset the
> interpreter back to a fresh state, or, even better, a fresh state +
> keeping some required ruby-gems.
>
> My goal is to make a continuos test runner, and avoid the overhead of
> having to restart ruby and require the gems each times.
>
> I could do this with fork (copy-on-write), except I want this to
> run on
> Win32 as well.
>
> Any ideas?
>
> --
> Posted via http://www.ruby-....
>

I'm confused, why do you need to "reset" ruby everytime? Can't you
stick the tests in a loop?


List Recv

1/16/2006 1:48:00 AM

0

Logan Capaldo wrote:
> I'm confused, why do you need to "reset" ruby everytime? Can't you
> stick the tests in a loop?

The code - and it's require files - are constantly changing. (That's
the whole point of continuos testing!). I want to a) make sure to
reload all required files and b) make sure to start with a fresh slate,
in terms of class definitions, ObjectSpace, and the like.

--
Posted via http://www.ruby-....


Logan Capaldo

1/16/2006 1:59:00 AM

0


On Jan 15, 2006, at 8:47 PM, List Recv wrote:

> Logan Capaldo wrote:
>> I'm confused, why do you need to "reset" ruby everytime? Can't you
>> stick the tests in a loop?
>
> The code - and it's require files - are constantly changing. (That's
> the whole point of continuos testing!). I want to a) make sure to
> reload all required files and b) make sure to start with a fresh
> slate,
> in terms of class definitions, ObjectSpace, and the like.
>
> --
> Posted via http://www.ruby-....
>

Ok, so change the 'require's to 'load's and then stick it in a
loop ;). In seriousness though, all the work involved with undefining
everything, and you might as well just start a new ruby executable.
Perhaps I'm not understanding you correctly, how would you do this
with fork, and avoid the overhead of requiring things?



List Recv

1/16/2006 5:03:00 AM

0

Logan Capaldo wrote:
> On Jan 15, 2006, at 8:47 PM, List Recv wrote:
>
>> --
>> Posted via http://www.ruby-....
>>
>
> Ok, so change the 'require's to 'load's and then stick it in a
> loop ;). In seriousness though, all the work involved with undefining
> everything, and you might as well just start a new ruby executable.
> Perhaps I'm not understanding you correctly, how would you do this
> with fork, and avoid the overhead of requiring things?

fork would save the overhead of loading ruby itself

--
Posted via http://www.ruby-....


Jacob Fugal

1/16/2006 5:35:00 AM

0

On 1/15/06, List Recv <listrecv@gmail.com> wrote:
> Logan Capaldo wrote:
> > Ok, so change the 'require's to 'load's and then stick it in a
> > loop ;). In seriousness though, all the work involved with undefining
> > everything, and you might as well just start a new ruby executable.
> > Perhaps I'm not understanding you correctly, how would you do this
> > with fork, and avoid the overhead of requiring things?
>
> fork would save the overhead of loading ruby itself

However, with fork you'd need to be careful about open filehandles and
the like which are shared between the processes. Getting consistent
results between a stay alive process like this and a new process each
time can be really tricky.

Jacob Fugal


Logan Capaldo

1/16/2006 5:46:00 AM

0


On Jan 16, 2006, at 12:39 AM, Jacob Fugal wrote:

> On 1/15/06, Logan Capaldo <logancapaldo@gmail.com> wrote:
>>
>> Ok, so change the 'require's to 'load's and then stick it in a
>> loop ;).
>
> That's not quite sufficient. 'load' simply loads the file again. It
> doesn't replace the result of previously loading the file. So if the
> "signature" of the file is the same (all the same classes, methods,
> variables, etc. declared only with different values/implementations)
> you're good. But in the more frequent case where the signature changes
> in a non-additive way (e.g. a method is removed), that change is *not*
> propagated by a new load. That means the method that was removed is
> still available within the test script, which may cause some tests to
> pass which should fail and would fail if run under a new instance.
>
> Jacob Fugal
>

I know, hence the smiley face. I still think this idea is a little
extreme for the minor savings you'd get out of it.


Dalibor Sramek

1/16/2006 11:33:00 AM

0

On Mon, Jan 16, 2006 at 02:45:46PM +0900, Logan Capaldo wrote:
> I know, hence the smiley face. I still think this idea is a little
> extreme for the minor savings you'd get out of it.

The possibility to reset the interpreter would be IMHO useful also for other
situations where you have persistent Ruby processes (think mod_ruby).

Dalibor Sramek

--
Dalibor Sramek http://www.insu... \ In the eyes of cats
/ dalibor.sramek@insula.cz \ all things
/ >H blog http://www.transhumanismus.c... \ belong to cats.


Mark Volkmann

1/16/2006 1:43:00 PM

0

On 1/16/06, Dalibor Sramek <dali@insula.cz> wrote:
> On Mon, Jan 16, 2006 at 02:45:46PM +0900, Logan Capaldo wrote:
> > I know, hence the smiley face. I still think this idea is a little
> > extreme for the minor savings you'd get out of it.
>
> The possibility to reset the interpreter would be IMHO useful also for other
> situations where you have persistent Ruby processes (think mod_ruby).

It would also be useful for debuggers so you could rerun the program
without having to re-enter breakpoints. As far as I know, this isn't
currently possible with the built-in Ruby debugger. Can any Ruby
debuggers do this now?

--
R. Mark Volkmann
Partner, Object Computing, Inc.


Eivind Eklund

1/16/2006 2:17:00 PM

0

On 1/16/06, List Recv <listrecv@gmail.com> wrote:
> I'm looking for a fast way to "reset" Ruby. That is, to reset the
> interpreter back to a fresh state, or, even better, a fresh state +
> keeping some required ruby-gems.
>
> My goal is to make a continuos test runner, and avoid the overhead of
> having to restart ruby and require the gems each times.

I've got code for this kind of testrunner; no specific optimizations,
though. It's a plain testrunner using pipes for communication and a
fork to separate out the execution. There's something clumsy about it
- I don't remember what it was.

If you're dead set on doing this inside a single Ruby process, this
won't help - if you want an easy way out, I'll try to dig up the code
- it wasn't in the obvious places :-/

Eivind.


John W. Long

1/16/2006 2:38:00 PM

0

List Recv wrote:
> I'm looking for a fast way to "reset" Ruby. That is, to reset the
> interpreter back to a fresh state, or, even better, a fresh state +
> keeping some required ruby-gems.
>
> My goal is to make a continuous test runner, and avoid the overhead of
> having to restart ruby and require the gems each times.

One thing you could do would be to load up all of your libraries and
pause on the terminal waiting for user input. As soon as the user
unpaused the process it would load in the test cases and run them. As
the user was looking at the output and fixing tests you could load up
another instance and pause waiting for user input. Stir and repeat...

I've thought for a long time that something like this would be very
useful for Rails testing where loading up the library code takes 2-3
seconds, making unit testing tedious.

--
John Long
http://wiseheart...