is timeout.rb fixed in 1.9.2?

Discussion in 'Ruby' started by bill walton, Sep 28, 2012.

  1. bill walton

    bill walton Guest

    bill walton, Sep 28, 2012
    #1
    1. Advertisements

  2. You can check for yourself:
    https://bugs.ruby-lang.org/issues/4285

    Note, while looking into this I opened a few bugs today:
    https://bugs.ruby-lang.org/issues/7086
    https://bugs.ruby-lang.org/issues/7087
    https://bugs.ruby-lang.org/issues/7088

    :)

    My solution timeout_1 could be used but it will keep the background
    thread running. You could change it like so:

    def timeout_5(timeout, &code)
    raise ArgumentError, "Invalid timeout: %p" % [timeout] unless timeout > 0
    raise ArgumentError, "No code to execute" if code.nil?

    worker = Thread.new(&code)

    if worker.join(timeout)
    worker.value
    else
    worker.kill rescue nil
    # worker.raise Exception, "Stop"
    nil
    end
    end


    Kind regards

    robert
     
    Robert Klemme, Sep 29, 2012
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.