๐
jjb / better_timeout Goto Github PK
View Code? Open in Web Editor NEWFixing Ruby's standard library Timeout
License: MIT License
Fixing Ruby's standard library Timeout
License: MIT License
๐
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?
--- 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
}
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.