IO.select timeout problem

Discussion in 'Ruby' started by sgibson, Jul 10, 2008.

  1. sgibson

    sgibson Guest

    Using ruby 1.8.6 under Linux. For some reason IO.select() seems to be
    ignoring the 'timeout' parameter. Regardless of what value I put in
    there (float or integer) it doesn't seem to have any effect -- if
    there isn't any data available on stdout or stderr, select() just
    waits until there is data:

    @stdin, @stdout, @stderr = Open3.popen3("./myprog")
    return_data = ""
    loop do
    while result = select([@stdout, @stderr], nil, nil, 0.25)
    for data in result[0]
    if data == @stdout
    return_data = return_data + @stdout.gets
    logit("debug: return_data = " + return_data)
    elsif data == @stderr
    return_data = return_data + @stderr.gets
    end
    end # for
    end # while
    logit("debug: timed out -- waiting for data...")
    if return_data != ""
    send_to_user(return_data)
    return_data = ""
    end
    end # loop


    Am I missing something?

    -Steve
    sgibson, Jul 10, 2008
    #1
    1. Advertising

  2. sgibson

    inspire Guest

    I'm having this same problem - wish I had a better solution to offer
    you! Perhaps it's just broken this version of linux, or something
    more complicated in the code is causing problems..

    Linux 2.6.18

    It must be something more complicated in the code ,as this works fine:
    loop do
    while result = select([], nil, nil, 0.25)
    puts "GOT RESULT";
    end
    puts "looped"
    end

    Ciao,
    Kevin

    sgibson wrote:
    > Using ruby 1.8.6 under Linux. For some reason IO.select() seems to be
    > ignoring the 'timeout' parameter. Regardless of what value I put in
    > there (float or integer) it doesn't seem to have any effect -- if
    > there isn't any data available on stdout or stderr, select() just
    > waits until there is data:
    >
    > @stdin, @stdout, @stderr = Open3.popen3("./myprog")
    > return_data = ""
    > loop do
    > while result = select([@stdout, @stderr], nil, nil, 0.25)
    > for data in result[0]
    > if data == @stdout
    > return_data = return_data + @stdout.gets
    > logit("debug: return_data = " + return_data)
    > elsif data == @stderr
    > return_data = return_data + @stderr.gets
    > end
    > end # for
    > end # while
    > logit("debug: timed out -- waiting for data...")
    > if return_data != ""
    > send_to_user(return_data)
    > return_data = ""
    > end
    > end # loop
    >
    >
    > Am I missing something?
    >
    > -Steve
    inspire, Jul 10, 2008
    #2
    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. Bob Johnson
    Replies:
    0
    Views:
    3,723
    Bob Johnson
    Aug 7, 2003
  2. Do
    Replies:
    2
    Views:
    6,325
  3. Paul  Moore
    Replies:
    16
    Views:
    1,740
    Paul Kölle
    May 9, 2010
  4. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,250
    Brian Candler
    Oct 6, 2004
  5. palmiere
    Replies:
    1
    Views:
    312
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page