Git Product home page Git Product logo

better_timeout's Introduction

Better Timeout

This is a fork of ruby 1.9.3 timeout which has the following behavior change:

Regardless of what errors the timed code catches, Timeout.timeout will always raise an exception if the code times out.

The stack traces might also be nicer, but this is still be full tested.

When the gem is installed, better_timeout takes over Timeout.timeout in all cases.

Installation

Add this line to your application's Gemfile:

gem 'better_timeout', git: 'https://github.com/jjb/better_timeout' # not in rubygems yet, need to install from git

And then execute:

$ bundle

Or install it yourself as:

$ gem install better_timeout

Discussion/findings

In standlib

  • same type of error is raised inside thread and outside when specified
  • when not specified, Exception is raised inside, StandardError is raised outside

this project was formerly named sane_timeout

better_timeout's People

Contributors

jjb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sportngin

better_timeout's Issues

Is it really sane and safe?

http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html

Although you don't have to take my word for it, eventually you're going to have to accept the truth. Thread#kill, Thread#raise, timeout.rb, net/protocol.rb all suffer from these problems. net/protocol.rb could be fixed to use nonblocking IO (select), as could I suspect most of the other libraries, but there is no safe way to use Thread#kill or Thread#raise. Let me repeat that: there is no safe way to use Thread#kill or Thread#raise.

Has anything changed since 2008? Is it really safe to use this gem?

Thanks for this library!

Thanks for this. It's one of the only implementations of a timeout in ruby that will actually timeout when it is supposed to. One problem we had with it is that we don't want to use it for everything just specific http requests. Would you be open to accepting a PR that wraps the entire library in a SaneTimeout module? Namespacing it and allow it to be used at will vs requiring it to be used on every timeout has worked very well for us. Here are the changes we've made so far master...sportngin:master

idea: ability to specify ensure seconds

--- a/lib/better_timeout.rb
+++ b/lib/better_timeout.rb
@@ -64,7 +64,7 @@ module Timeout
             x.raise e
           else
             x.raise exception, "execution expired"
-            x.join
+            x.join(3.1)#(ensure_seconds) <-- this can be a feature of better timeout - option to give inner code ensure_seconds for ensure to finish
             current_thread.raise exception, "execution expired"
           end
         }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.