WEBrick causing ruby process to hang? (on windows)

Discussion in 'Ruby' started by Kevin M, Sep 20, 2004.

  1. Kevin M

    Kevin M Guest

    When I run a ruby script that uses webrick, it seems to hang on exit.
    I'm using ruby 1.8.2 on Windows XP. (I don't remember having this
    sort of problem using linux, but I don't have a machine here to verify
    that.)

    For example, if I run the following:

    require 'webrick'

    server = WEBrick::HTTPServer.new(
    :port => 8081,
    :DocumentRoot => '.'
    )

    ['INT', 'TERM'].each {|signal| trap(signal) {
    puts "got #{signal}, shutting down..."
    server.shutdown
    puts "OK"
    }}
    server.start

    This will start up fine, but on hitting CTRL-C it'll display both
    'puts', and then hang. I have to kill the process with task manager.

    Any thoughts as to what I'm doing wrong?

    Cheers,
    Kevin
    Kevin M, Sep 20, 2004
    #1
    1. Advertising

  2. I had a number of problems with this, which turned out to be related
    to keep-alive connections, not Windows signal-handling.

    Try disabling keep-alive, (either in your HTML head section, or using
    raw headers in your servlets) and see if the process shuts down
    normally.


    --
    Lennon
    rcoder.net
    Lennon Day-Reynolds, Sep 20, 2004
    #2
    1. Advertising

  3. Kevin M

    Kevin M Guest

    Just to follow up... I checked on my home machines (one Linux, one Max
    OS X) and they were both fine using that same piece of sample code.
    So it definately just seems to be Windows. (Or perhaps it's just *my*
    Windows machine :)

    It's annoying though, as it really slows down the edit/test cycle...

    Kevin
    Kevin M, Sep 21, 2004
    #3
  4. On Tue, Sep 21, 2004 at 01:59:37PM +0900, Kevin M wrote:
    > Just to follow up... I checked on my home machines (one Linux, one Max
    > OS X) and they were both fine using that same piece of sample code.
    > So it definately just seems to be Windows. (Or perhaps it's just *my*
    > Windows machine :)
    >
    > It's annoying though, as it really slows down the edit/test cycle...


    if the issue here is that you are shutting down webrick frequently because
    you are developing and want to test then you can feed :auto_reload =>
    true to webrick's option hash.

    it will auto-reload all the classes on each request.

    marcel
    --
    Marcel Molina Jr. <>
    Marcel Molina Jr., Sep 21, 2004
    #4
  5. Kevin M

    Pit Capitain Guest

    Kevin McConnell schrieb:
    > Later, when I have some more time, I'll see if I can find the cause of
    > the hanging.


    Hi Kevin,

    I found this while looking at some old code of mine:

    trap("INT"){ s.shutdown; raise IOError }

    With this I could shutdown WEBrick hitting CTRL-C in the DOS window. The raise
    was necessary, but I don't remember why.

    HTH

    Pit
    Pit Capitain, Sep 22, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesse Cates via DotNetMonster.com

    Process.Start is causes application to hang

    Jesse Cates via DotNetMonster.com, Jan 28, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,530
    Steve C. Orr [MVP, MCSD]
    Jan 31, 2005
  2. Nishi Bhonsle
    Replies:
    2
    Views:
    23,520
    pahujadeepanshu
    Nov 30, 2009
  3. Lloyd Zusman
    Replies:
    2
    Views:
    382
  4. Aaron Smith

    WEBrick::Daemon and WEBrick

    Aaron Smith, Mar 9, 2007, in forum: Ruby
    Replies:
    2
    Views:
    301
    Aaron Smith
    Mar 18, 2007
  5. Cosmic Cruizer

    Perl causing scheduler to hang

    Cosmic Cruizer, Feb 22, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    92
    Cosmic Cruizer
    Feb 22, 2004
Loading...

Share This Page