[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

interacting with ruby program

Navindra Umanee

1/31/2005 4:22:00 PM

Hi,

Are there any nice or existing solutions for attaching to a running
Ruby process and changing the code on the fly from the console?

Like, say I want to update a variable or modify a method for a Ruby
program that is already running. I guess maybe the Ruby program would
have to allocate a thread/socket for eval requests... it would be
nice if someone already solved this.

Thanks,
Navin.


21 Answers

Robert Klemme

1/31/2005 4:27:00 PM

0


"Navindra Umanee" <navindra@cs.mcgill.ca> schrieb im Newsbeitrag
news:20050131112202.A11120@cs.mcgill.ca...
> Hi,
>
> Are there any nice or existing solutions for attaching to a running
> Ruby process and changing the code on the fly from the console?
>
> Like, say I want to update a variable or modify a method for a Ruby
> program that is already running. I guess maybe the Ruby program would
> have to allocate a thread/socket for eval requests... it would be
> nice if someone already solved this.

Didn't solve this yet, but you could certainly cook something up quite
easily with webrick: just throw out a form with a field for code to enter
and when pressing the button the code is executed and the result is sent
back. That way you can use any browser to access it.

Just my 0.02EUR...

Kind regards

robert

Navindra Umanee

1/31/2005 4:48:00 PM

0

Robert Klemme <bob.news@gmx.net> wrote:
> Didn't solve this yet, but you could certainly cook something up quite
> easily with webrick: just throw out a form with a field for code to enter
> and when pressing the button the code is executed and the result is sent
> back. That way you can use any browser to access it.

Hmmm, yeah, not yet sure if webrick is an option for me. Need to be
robust and Apache will have to remain on the frontline for other
reasons as well... but I guess it could proxy to webrick.

Thanks for the pointer. I'm still interested in non-webrick based
solutions if anyone has them.

Cheers,
Navin.


Robert Klemme

1/31/2005 6:25:00 PM

0


"Navindra Umanee" <navindra@cs.mcgill.ca> schrieb im Newsbeitrag
news:20050131114723.B11175@cs.mcgill.ca...
> Robert Klemme <bob.news@gmx.net> wrote:
> > Didn't solve this yet, but you could certainly cook something up quite
> > easily with webrick: just throw out a form with a field for code to
enter
> > and when pressing the button the code is executed and the result is
sent
> > back. That way you can use any browser to access it.
>
> Hmmm, yeah, not yet sure if webrick is an option for me. Need to be
> robust and Apache will have to remain on the frontline for other
> reasons as well... but I guess it could proxy to webrick.
>
> Thanks for the pointer. I'm still interested in non-webrick based
> solutions if anyone has them.

Didn't know that you have a webserver already. Of course you can use that
(CGI with a proxy script that connects via DRB for example). If that
webserver is publicly available you better make sure that no malicious
code is executed.

Kind regards

robert

Matt Mower

1/31/2005 6:49:00 PM

0

On Tue, 1 Feb 2005 01:22:17 +0900, Navindra Umanee
<navindra@cs.mcgill.ca> wrote:
> Are there any nice or existing solutions for attaching to a running
> Ruby process and changing the code on the fly from the console?
>

I don't know if this is possible or not but I seem to remember that
irb has job control. Could you maybe start your app from within irb,
either as a background job or maybe by spawning it in a thread?

Regards,

Matt
--
Matt Mower :: http://matt...


Florian Gross

1/31/2005 7:54:00 PM

0

Navindra Umanee wrote:

> Are there any nice or existing solutions for attaching to a running
> Ruby process and changing the code on the fly from the console?
>
> Like, say I want to update a variable or modify a method for a Ruby
> program that is already running. I guess maybe the Ruby program would
> have to allocate a thread/socket for eval requests... it would be
> nice if someone already solved this.

This would be possible by using a secondary thread that keeps spawning
up breakpoints. E.g.:

require 'breakpoint'
Thread.new do
loop do
begin
breakpoint
rescue Exception
end
end
end

After that you could use the breakpoint_client to get a live shell where
you could change and check basically everything.

If you want to execute the breakpoints in a different context you can
use breakpoint(nil, TOPLEVEL_BINDING) or breakpoint(nil,
obj.send(:binding)).

Martin DeMello

1/31/2005 7:56:00 PM

0

Navindra Umanee <navindra@cs.mcgill.ca> wrote:
> Robert Klemme <bob.news@gmx.net> wrote:
> > Didn't solve this yet, but you could certainly cook something up quite
> > easily with webrick: just throw out a form with a field for code to enter
> > and when pressing the button the code is executed and the result is sent
> > back. That way you can use any browser to access it.
>
> Hmmm, yeah, not yet sure if webrick is an option for me. Need to be
> robust and Apache will have to remain on the frontline for other
> reasons as well... but I guess it could proxy to webrick.

Why not just run webrick on an entirely separate port?

martin

Navindra Umanee

1/31/2005 8:03:00 PM

0

Matt Mower <matt.mower@gmail.com> wrote:
> I don't know if this is possible or not but I seem to remember that
> irb has job control. Could you maybe start your app from within irb,
> either as a background job or maybe by spawning it in a thread?

Oh. I can't figure out how to run something as a background job:

irb(main):001:0> irb # new job
irb#1(main):001:0> booga = "booga"
=> "booga"
irb#1(main):002:0> while true; p booga; sleep 2; end
"booga"
"booga"
"booga"
"booga"
IRB::Abort: abort then interrupt!!
from /usr/lib/ruby/1.8/irb.rb:81
irb#1(main):003:0>

It's in the foreground and if I press Control-C, it aborts. Control-Z
suspends the IRB process itself. Is there some way of backgrounding a
job so that variables can be modified?

I can run it in a new thread like this:

irb(main):001:0> booga = "booga"
=> "booga"
irb(main):002:0> x = Thread.new { while true; p booga; sleep 2; end }
"booga"=> #<Thread:0x402caab0 run>
irb(main):003:0>
"booga"
"booga"

irb(main):004:0* jobs
=> #0->irb on main (#<Thread:0x4029f798>: running)
irb(main):005:0> booga = "blah"
=> "blah"
irb(main):006:0> "blah"
"blah"

That seems to work. Is irb a robust solution?

Thanks,
Navin.


Dick Davies

1/31/2005 8:08:00 PM

0

* Navindra Umanee <navindra@cs.mcgill.ca> [0122 16:22]:
> Hi,
>
> Are there any nice or existing solutions for attaching to a running
> Ruby process and changing the code on the fly from the console?
>
> Like, say I want to update a variable or modify a method for a Ruby
> program that is already running. I guess maybe the Ruby program would
> have to allocate a thread/socket for eval requests... it would be
> nice if someone already solved this.

This sounds a lot like the breakpoint console in Rails - if you haven't
seen that yet, have a look.

--
'That question was less stupid; though you asked it in a profoundly stupid way.'
-- Prof. Farnsworth
Rasputin :: Jack of All Trades - Master of Nuns


Navindra Umanee

1/31/2005 8:08:00 PM

0

Florian Gross <flgr@ccan.de> wrote:
> This would be possible by using a secondary thread that keeps spawning
> up breakpoints. E.g.:

Interesting. Thanks for this easy looking solution!

> require 'breakpoint'

I can't seem to find this in: ruby 1.8.2 (2004-12-25) [i586-linux-gnu]

Is this an external package?

> Thread.new do
> loop do
> begin
> breakpoint
> rescue Exception
> end
> end
> end

Do you think this would be expensive or does breakpoint simply block
until it gets a connection?

> After that you could use the breakpoint_client to get a live shell where
> you could change and check basically everything.
>
> If you want to execute the breakpoints in a different context you can
> use breakpoint(nil, TOPLEVEL_BINDING) or breakpoint(nil,
> obj.send(:binding)).

Thank you very much!

Martin: Yup, that's what I meant by proxy to webrick.

Cheers,
Navin.


Florian Gross

1/31/2005 8:12:00 PM

0

Navindra Umanee wrote:

>>require 'breakpoint'
>
> I can't seem to find this in: ruby 1.8.2 (2004-12-25) [i586-linux-gnu]
>
> Is this an external package?

Yup, it's available as part of the Rails package, but I can also mail it
to you privately.

>>Thread.new do
>> loop do
>> begin
>> breakpoint
>> rescue Exception
>> end
>> end
>>end
>
> Do you think this would be expensive or does breakpoint simply block
> until it gets a connection?

It simply blocks so it ought to be reasonably cheap.