111 lines
10 KiB
HTML
111 lines
10 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html ><head ><title >Python: module func_timeout.dafunc</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
</head><body bgcolor="#f0f0f8" >
|
|
|
|
<table width="100%" cellspacing="0" cellpadding="2" border="0" summary="heading" >
|
|
<tr bgcolor="#7799ee" >
|
|
<td valign="bottom" > <br />
|
|
<font color="#ffffff" face="helvetica, arial" > <br /><big ><big ><strong ><a href="func_timeout.html" ><font color="#ffffff" >func_timeout</font></a>.dafunc</strong></big></big></font></td><td align="right" valign="bottom" ><font color="#ffffff" face="helvetica, arial" ><a href="func_timeout.html" >index</a></font></td></tr></table>
|
|
<p ><tt >Copyright (c) 2016, 2017 Tim Savannah All Rights Reserved.<br />
|
|
<br />
|
|
Licensed under the Lesser GNU Public License Version 3, LGPLv3. You should have recieved a copy of this with the source distribution as<br />
|
|
LICENSE, otherwise it is available at https://github.com/kata198/func_timeout/LICENSE</tt></p>
|
|
<p >
|
|
<table width="100%" cellspacing="0" cellpadding="2" border="0" summary="section" >
|
|
<tr bgcolor="#aa55cc" >
|
|
<td colspan="3" valign="bottom" > <br />
|
|
<font color="#ffffff" face="helvetica, arial" ><big ><strong >Modules</strong></big></font></td></tr>
|
|
|
|
<tr ><td bgcolor="#aa55cc" ><tt > </tt></td><td > </td>
|
|
<td width="100%" ><table width="100%" summary="list" ><tr ><td width="25%" valign="top" ><a href="copy.html" >copy</a><br />
|
|
<a href="inspect.html" >inspect</a><br />
|
|
</td><td width="25%" valign="top" ><a href="sys.html" >sys</a><br />
|
|
<a href="threading.html" >threading</a><br />
|
|
</td><td width="25%" valign="top" ><a href="time.html" >time</a><br />
|
|
<a href="types.html" >types</a><br />
|
|
</td><td width="25%" valign="top" ></td></tr></table></td></tr></table><p >
|
|
<table width="100%" cellspacing="0" cellpadding="2" border="0" summary="section" >
|
|
<tr bgcolor="#eeaa77" >
|
|
<td colspan="3" valign="bottom" > <br />
|
|
<font color="#ffffff" face="helvetica, arial" ><big ><strong >Functions</strong></big></font></td></tr>
|
|
|
|
<tr ><td bgcolor="#eeaa77" ><tt > </tt></td><td > </td>
|
|
<td width="100%" ><dl ><dt ><a name="-func_set_timeout" ><strong >func_set_timeout</strong></a>(timeout, allowOverride=False)</dt><dd ><tt >func_set_timeout - Decorator to run a function with a given/calculated timeout (max execution time).<br />
|
|
Optionally (if #allowOverride is True), adds a paramater, "forceTimeout", to the<br />
|
|
function which, if provided, will override the default timeout for that invocation.<br />
|
|
<br />
|
|
If #timeout is provided as a lambda/function, it will be called<br />
|
|
prior to each invocation of the decorated function to calculate the timeout to be used<br />
|
|
for that call, based on the arguments passed to the decorated function.<br />
|
|
<br />
|
|
For example, you may have a "processData" function whose execution time<br />
|
|
depends on the number of "data" elements, so you may want a million elements to have a<br />
|
|
much higher timeout than seven elements.)<br />
|
|
<br />
|
|
If #allowOverride is True AND a kwarg of "forceTimeout" is passed to the wrapped function, that timeout<br />
|
|
will be used for that single call.<br />
|
|
<br />
|
|
@param timeout <float OR lambda/function> -<br />
|
|
<br />
|
|
**If float:**<br />
|
|
Default number of seconds max to allow function to execute<br />
|
|
before throwing FunctionTimedOut<br />
|
|
<br />
|
|
**If lambda/function:<br />
|
|
<br />
|
|
If a function/lambda is provided, it will be called for every<br />
|
|
invocation of the decorated function (unless #allowOverride=True and "forceTimeout" was passed)<br />
|
|
to determine the timeout to use based on the arguments to the decorated function.<br />
|
|
<br />
|
|
The arguments as passed into the decorated function will be passed to this function.<br />
|
|
They either must match exactly to what the decorated function has, OR<br />
|
|
if you prefer to get the *args (list of ordered args) and **kwargs ( key : value keyword args form),<br />
|
|
define your calculate function like:<br />
|
|
<br />
|
|
def calculateTimeout(*args, **kwargs):<br />
|
|
...<br />
|
|
<br />
|
|
or lambda like:<br />
|
|
<br />
|
|
calculateTimeout = lambda *args, **kwargs : ...<br />
|
|
<br />
|
|
otherwise the args to your calculate function should match exactly the decorated function.<br />
|
|
<br />
|
|
<br />
|
|
@param allowOverride <bool> Default False, if True adds a keyword argument to the decorated function,<br />
|
|
"forceTimeout" which, if provided, will override the #timeout. If #timeout was provided as a lambda / function, it<br />
|
|
will not be called.<br />
|
|
<br />
|
|
@throws FunctionTimedOut If time alloted passes without function returning naturally<br />
|
|
<br />
|
|
@see func_timeout</tt></dd></dl>
|
|
<dl ><dt ><a name="-func_timeout" ><strong >func_timeout</strong></a>(timeout, func, args=(), kwargs=None)</dt><dd ><tt >func_timeout - Runs the given function for up to #timeout# seconds.<br />
|
|
<br />
|
|
Raises any exceptions #func# would raise, returns what #func# would return (unless timeout is exceeded), in which case it raises FunctionTimedOut<br />
|
|
<br />
|
|
@param timeout <float> - Maximum number of seconds to run #func# before terminating<br />
|
|
<br />
|
|
@param func <function> - The function to call<br />
|
|
<br />
|
|
@param args <tuple> - Any ordered arguments to pass to the function<br />
|
|
<br />
|
|
@param kwargs <dict/None> - Keyword arguments to pass to the function.<br />
|
|
<br />
|
|
<br />
|
|
@raises - FunctionTimedOut if #timeout# is exceeded, otherwise anything #func# could raise will be raised<br />
|
|
<br />
|
|
If the timeout is exceeded, FunctionTimedOut will be raised within the context of the called function every two seconds until it terminates,<br />
|
|
but will not block the calling thread (a new thread will be created to perform the join). If possible, you should try/except FunctionTimedOut<br />
|
|
to return cleanly, but in most cases it will 'just work'.<br />
|
|
<br />
|
|
@return - The return value that #func# gives</tt></dd></dl>
|
|
</td></tr></table><p >
|
|
<table width="100%" cellspacing="0" cellpadding="2" border="0" summary="section" >
|
|
<tr bgcolor="#55aa55" >
|
|
<td colspan="3" valign="bottom" > <br />
|
|
<font color="#ffffff" face="helvetica, arial" ><big ><strong >Data</strong></big></font></td></tr>
|
|
|
|
<tr ><td bgcolor="#55aa55" ><tt > </tt></td><td > </td>
|
|
<td width="100%" ><strong >__all__</strong> = ('func_timeout', 'func_set_timeout')</td></tr></table>
|
|
</p></p></p></body></html> |