Popular recipes tagged "timeout"http://code.activestate.com/recipes/tags/timeout/2013-05-24T05:19:50-07:00ActiveState Code RecipesRetry loop (Python)
2013-05-23T20:45:01-07:00Ryan Nowakowskihttp://code.activestate.com/recipes/users/4186624/http://code.activestate.com/recipes/578527-retry-loop/
<p style="color: grey">
Python
recipe 578527
by <a href="/recipes/users/4186624/">Ryan Nowakowski</a>
(<a href="/recipes/tags/exception/">exception</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/loop/">loop</a>, <a href="/recipes/tags/retry/">retry</a>, <a href="/recipes/tags/timeout/">timeout</a>).
</p>
<p>Encapsulates the logic of a retry loop using a generator function.</p>
Retry loop (Python)
2013-05-24T05:19:50-07:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578163-retry-loop/
<p style="color: grey">
Python
recipe 578163
by <a href="/recipes/users/2033964/">Oren Tirosh</a>
(<a href="/recipes/tags/exception/">exception</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/loop/">loop</a>, <a href="/recipes/tags/retry/">retry</a>, <a href="/recipes/tags/timeout/">timeout</a>).
Revision 4.
</p>
<p>Encapsulates the logic of a retry loop using a generator function.</p>
Wait for PID and check for PID existance (POSIX) (Python)
2012-04-15T14:13:02-07:00Giampaolo RodolĂ http://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/578022-wait-for-pid-and-check-for-pid-existance-posix/
<p style="color: grey">
Python
recipe 578022
by <a href="/recipes/users/4178764/">Giampaolo RodolĂ </a>
(<a href="/recipes/tags/exists/">exists</a>, <a href="/recipes/tags/exit/">exit</a>, <a href="/recipes/tags/pid/">pid</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/status/">status</a>, <a href="/recipes/tags/timeout/">timeout</a>, <a href="/recipes/tags/wait/">wait</a>).
Revision 7.
</p>
<p>Two functions: one which waits for a certain PID to terminate (with optional timeout), another one which checks whether a process with a given PID is running.</p>
<p>This was extracted from <a href="http://code.google.com/p/psutil/">psutil</a> project which also provides a Windows implementation.</p>
<p>Timeout functionality is implemented as a busy loop and it was inspired by <a href="http://bugs.python.org/issue5673." rel="nofollow">http://bugs.python.org/issue5673.</a></p>
timeout decorator (with multiprocessing) (Python)
2011-08-23T05:25:09-07:00matt harrisonhttp://code.activestate.com/recipes/users/4179061/http://code.activestate.com/recipes/577853-timeout-decorator-with-multiprocessing/
<p style="color: grey">
Python
recipe 577853
by <a href="/recipes/users/4179061/">matt harrison</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>, <a href="/recipes/tags/timeout/">timeout</a>).
</p>
<p>Given that threads shouldn't be killed, multiprocessing is one mechanism for limiting time on a potentially long running computation.</p>
RSH with timeout (Python)
2010-09-13T06:49:35-07:00Shrinidhi Raohttp://code.activestate.com/recipes/users/4174946/http://code.activestate.com/recipes/577390-rsh-with-timeout/
<p style="color: grey">
Python
recipe 577390
by <a href="/recipes/users/4174946/">Shrinidhi Rao</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/execution/">execution</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/rsh/">rsh</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/timeout/">timeout</a>).
</p>
<p>RSH sometimes hangs if it cannot resolve to a given host. So here is a quick recipe in python </p>
Timeout Any Function (Python)
2010-02-04T17:36:31-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577028-timeout-any-function/
<p style="color: grey">
Python
recipe 577028
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/generic/">generic</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/timeout/">timeout</a>, <a href="/recipes/tags/universal_code/">universal_code</a>).
Revision 6.
</p>
<p>This recipe uses the <code>multiprocessing</code> module to kill functions that have run longer than intended. Unlike other recipes that use threading, this code is designed to actually kill execution that has continued for too long. This implementation does not rely on signals or anything that is OS specific, so it should work on any system on which you might need generic timeouts.</p>
Timeout for (nearly) any callable (Python)
2010-12-20T06:51:35-08:00Jean Brouwershttp://code.activestate.com/recipes/users/2984142/http://code.activestate.com/recipes/576780-timeout-for-nearly-any-callable/
<p style="color: grey">
Python
recipe 576780
by <a href="/recipes/users/2984142/">Jean Brouwers</a>
(<a href="/recipes/tags/threads/">threads</a>, <a href="/recipes/tags/timeout/">timeout</a>).
Revision 5.
</p>
<p>This recipe provides 2 ways to invoke any callable with a time limit. Usable for Python 2.2 thru 3.0, see the Note in the module __doc__.</p>