[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

WEBrick catching keyboard interrupts

Alex Young

10/5/2006 8:47:00 AM

Hi all,

I'm knocking up a few test scripts using WEBrick (on Ubuntu), and I'm
constantly annoyed by the fact that hitting Ctrl-C doesn't kill it, but
makes it print the following to the console:

[2006-10-05 09:43:48] ERROR Interrupt:
/usr/lib/ruby/1.8/webrick/server.rb:91:in `select'

I have to go to another console (or suspend it) and kill -9 the process.
How can I stop this from happening? The code is very, very simple:

require 'xmlrpc/server'

class Server < XMLRPC::Server
def initialize
super(8080, '0.0.0.0', 1)
self.add_handler('test.unit'){ 1 }
self.serve
end
end

Server.new

I'm sure there's a simple answer, but it eludes me...

--
Alex

9 Answers

MonkeeSage

10/5/2006 11:15:00 AM

0

Alex Young wrote:
> I have to go to another console (or suspend it) and kill -9 the process.
> How can I stop this from happening? The code is very, very simple:
>
> require 'xmlrpc/server'
>
> class Server < XMLRPC::Server
> def initialize
> super(8080, '0.0.0.0', 1)
> self.add_handler('test.unit'){ 1 }
> self.serve
> end
> end
>
> Server.new

Signal.trap(2) {
"Server killed (sigint)"
exit(1)
}

Regards,
Jordan

Alex Young

10/5/2006 11:39:00 AM

0

MonkeeSage wrote:
> Alex Young wrote:
>> I have to go to another console (or suspend it) and kill -9 the process.
>> How can I stop this from happening? The code is very, very simple:
>>
>> require 'xmlrpc/server'
>>
>> class Server < XMLRPC::Server
>> def initialize
>> super(8080, '0.0.0.0', 1)
>> self.add_handler('test.unit'){ 1 }
>> self.serve
>> end
>> end
>>
>> Server.new
>
> Signal.trap(2) {
> "Server killed (sigint)"
> exit(1)
> }
>
That gives me:

[2006-10-05 12:33:30] ERROR SystemExit: exit
test_server.rb:5:in `exit'

and a still-running process.

--
Alex

Alex Young

10/5/2006 11:41:00 AM

0

Alex Young wrote:
> MonkeeSage wrote:
>> Alex Young wrote:
>>> I have to go to another console (or suspend it) and kill -9 the process.
>>> How can I stop this from happening? The code is very, very simple:
>>>
>>> require 'xmlrpc/server'
>>>
>>> class Server < XMLRPC::Server
>>> def initialize
>>> super(8080, '0.0.0.0', 1)
>>> self.add_handler('test.unit'){ 1 }
>>> self.serve
>>> end
>>> end
>>>
>>> Server.new
>>
>> Signal.trap(2) {
>> "Server killed (sigint)"
>> exit(1)
>> }
>>
> That gives me:
>
> [2006-10-05 12:33:30] ERROR SystemExit: exit
> test_server.rb:5:in `exit'
>
> and a still-running process.
>
Sorry, should have said: That gives me the above error on Ctrl-C, and
repeats it for every time I send the interrupt, without ending the
process. Just thought I'd clarify that...

--
Alex

MonkeeSage

10/5/2006 11:59:00 AM

0

Alex Young wrote:
> Sorry, should have said: That gives me the above error on Ctrl-C, and
> repeats it for every time I send the interrupt, without ending the
> process. Just thought I'd clarify that...

I haven't used webrick much but it looks like it uses an exit hook.
Apparently you use the #shutdown method:

require 'xmlrpc/server'
class Server < XMLRPC::Server
def initialize
super(8080, '0.0.0.0', 1)
self.add_handler('test.unit'){ 1 }
self
end
def start
self.serve
end
end
server = Server.new
Signal.trap(2) {
puts "Server killed (sigint)"
server.shutdown
}
server.start

Regards,
Jordan

MonkeeSage

10/5/2006 12:04:00 PM

0

MonkeeSage wrote:
> I haven't used webrick much but it looks like it uses an exit hook.
> Apparently you use the #shutdown method:

Or better:

require 'xmlrpc/server'
class Server < XMLRPC::Server
def initialize
Signal.trap(2) {
puts "Server killed (sigint)"
self.shutdown
}
super(8080, '0.0.0.0', 1)
self.add_handler('test.unit'){ 1 }
self.serve
end
end
Server.new

Alex Young

10/5/2006 12:17:00 PM

0

MonkeeSage wrote:
> MonkeeSage wrote:
>> I haven't used webrick much but it looks like it uses an exit hook.
>> Apparently you use the #shutdown method:
>
> Or better:
>
> require 'xmlrpc/server'
> class Server < XMLRPC::Server
> def initialize
> Signal.trap(2) {
> puts "Server killed (sigint)"
> self.shutdown
> }
> super(8080, '0.0.0.0', 1)
> self.add_handler('test.unit'){ 1 }
> self.serve
> end
> end
> Server.new

Oh, of course... Thanks :-)

--
Alex

Bert Hyman

10/20/2008 4:48:00 PM

0

TigerLuck@wild_kingdom.afr (TigerLuck) wrote in
news:4l2Lk.4740$yr3.4034@nlpi068.nbdc.sbc.com:

> Bert Hyman wrote:
>>
>> Your man Obama; he's a church-going Christian, isn't he? Can his
>> rationality be assumed?
>>
>> It's a simple matter of "If you'll believe that, you'll believe
>> anything."
>>
>
> There is a big difference between a True Believer and one who
> assumes the mantle of a believer in order to aspire to elective
> office.

So, you're saying that Obama is just a simple liar, trying to fool
religious people into voting for him?

That's quite a ringing endorsement.

--
Bert Hyman | St. Paul, MN | bert@iphouse.com

TigerLuck

10/20/2008 4:57:00 PM

0

Bert Hyman wrote:
> TigerLuck@wild_kingdom.afr (TigerLuck) wrote in
> news:4l2Lk.4740$yr3.4034@nlpi068.nbdc.sbc.com:
>
>> Bert Hyman wrote:
>>> Your man Obama; he's a church-going Christian, isn't he? Can his
>>> rationality be assumed?
>>>
>>> It's a simple matter of "If you'll believe that, you'll believe
>>> anything."
>>>
>> There is a big difference between a True Believer and one who
>> assumes the mantle of a believer in order to aspire to elective
>> office.
>
> So, you're saying that Obama is just a simple liar, trying to fool
> religious people into voting for him?

If that's how you want to characterize the behavior of half the
Republican congress, so be it.

>
> That's quite a ringing endorsement.

It's a recognition of a political reality in this country, nothing more,
nothing less. Obama seems to be dealing with it as well as any other
politician, maybe better than most.

Having said that, I believe there is something of value in the teachings
of Jesus. I admit that sifting between those teachings that exhort one
to compassionate and humane behavior and those that tend to deify Jesus
takes a level of intelligence or wisdom that is a notch or two above
that of the majority of people.

It is the difference between trying to live up to an ideal of human
behavior and believing in the power of magical beings.

--
McCain calls for greater deregulation - March 25, 2008
http://www.youtube.com/watch?v=G...

I personally know William "Bill" Ayers
http://www.youtube.com/watch?v=q...

Sinatra & Sarah do Witchcraft
http://www.youtube.com/watch?v=r...

Meet Pastor Muthee -- the man who laid hands on Sarah Palin
http://www.youtube.com/watch?v=C...

Cyberiade.it Anonymous Remailer

10/20/2008 6:09:00 PM

0

In article <4l2Lk.4740$yr3.4034@nlpi068.nbdc.sbc.com>
TigerLuck <TigerLuck@wild_kingdom.afr> wrote:
>
>
> There is a big difference between a True Believer and one who assumes
> the mantle of a believer in order to aspire to elective office.

Is that why Obama believes it's okay for his priests to fuck 6
year old girls?