funboost 23.9__py3-none-any.whl → 24.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of funboost might be problematic. Click here for more details.

Files changed (79) hide show
  1. funboost/__init__.py +3 -1
  2. funboost/beggar_version_implementation/beggar_redis_consumer.py +1 -1
  3. funboost/concurrent_pool/flexible_thread_pool.py +140 -0
  4. funboost/consumers/base_consumer.py +2 -4
  5. funboost/consumers/local_python_queue_consumer.py +2 -1
  6. funboost/consumers/rabbitmq_amqpstorm_consumer.py +2 -1
  7. funboost/consumers/rabbitmq_pika_consumerv0.py +1 -0
  8. funboost/consumers/rabbitmq_rabbitpy_consumer.py +2 -1
  9. funboost/core/booster.py +2 -0
  10. funboost/core/get_booster.py +13 -0
  11. funboost/function_result_web/__pycache__/app.cpython-37.pyc +0 -0
  12. funboost/function_result_web/__pycache__/functions.cpython-37.pyc +0 -0
  13. funboost/publishers/local_python_queue_publisher.py +1 -1
  14. funboost/publishers/rabbitmq_amqpstorm_publisher.py +1 -1
  15. funboost/utils/dependency_packages_in_pythonpath/__pycache__/__init__.cpython-37.pyc +0 -0
  16. funboost/utils/dependency_packages_in_pythonpath/__pycache__/__init__.cpython-39.pyc +0 -0
  17. funboost/utils/dependency_packages_in_pythonpath/__pycache__/add_to_pythonpath.cpython-311.pyc +0 -0
  18. funboost/utils/dependency_packages_in_pythonpath/__pycache__/add_to_pythonpath.cpython-37.pyc +0 -0
  19. funboost/utils/dependency_packages_in_pythonpath/__pycache__/add_to_pythonpath.cpython-39.pyc +0 -0
  20. funboost/utils/dependency_packages_in_pythonpath/aioredis/__init__.py +59 -59
  21. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/__init__.cpython-311.pyc +0 -0
  22. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/__init__.cpython-37.pyc +0 -0
  23. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/__init__.cpython-39.pyc +0 -0
  24. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/client.cpython-311.pyc +0 -0
  25. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/client.cpython-37.pyc +0 -0
  26. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/client.cpython-39.pyc +0 -0
  27. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/compat.cpython-311.pyc +0 -0
  28. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/compat.cpython-37.pyc +0 -0
  29. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/compat.cpython-39.pyc +0 -0
  30. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/connection.cpython-311.pyc +0 -0
  31. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/connection.cpython-37.pyc +0 -0
  32. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/connection.cpython-39.pyc +0 -0
  33. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/exceptions.cpython-311.pyc +0 -0
  34. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/exceptions.cpython-37.pyc +0 -0
  35. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/exceptions.cpython-39.pyc +0 -0
  36. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/lock.cpython-311.pyc +0 -0
  37. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/lock.cpython-37.pyc +0 -0
  38. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/lock.cpython-39.pyc +0 -0
  39. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/utils.cpython-311.pyc +0 -0
  40. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/utils.cpython-37.pyc +0 -0
  41. funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/utils.cpython-39.pyc +0 -0
  42. funboost/utils/dependency_packages_in_pythonpath/aioredis/client.py +4804 -4804
  43. funboost/utils/dependency_packages_in_pythonpath/aioredis/compat.py +8 -8
  44. funboost/utils/dependency_packages_in_pythonpath/aioredis/connection.py +1668 -1668
  45. funboost/utils/dependency_packages_in_pythonpath/aioredis/exceptions.py +96 -96
  46. funboost/utils/dependency_packages_in_pythonpath/aioredis/lock.py +306 -306
  47. funboost/utils/dependency_packages_in_pythonpath/aioredis/log.py +15 -15
  48. funboost/utils/dependency_packages_in_pythonpath/aioredis/sentinel.py +329 -329
  49. funboost/utils/dependency_packages_in_pythonpath/aioredis/utils.py +61 -61
  50. funboost/utils/dependency_packages_in_pythonpath/func_timeout/StoppableThread.py +133 -133
  51. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__init__.py +16 -16
  52. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/StoppableThread.cpython-311.pyc +0 -0
  53. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/StoppableThread.cpython-37.pyc +0 -0
  54. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/StoppableThread.cpython-39.pyc +0 -0
  55. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/__init__.cpython-311.pyc +0 -0
  56. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/__init__.cpython-37.pyc +0 -0
  57. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/__init__.cpython-39.pyc +0 -0
  58. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/dafunc.cpython-311.pyc +0 -0
  59. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/dafunc.cpython-37.pyc +0 -0
  60. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/dafunc.cpython-39.pyc +0 -0
  61. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/exceptions.cpython-311.pyc +0 -0
  62. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/exceptions.cpython-37.pyc +0 -0
  63. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/exceptions.cpython-39.pyc +0 -0
  64. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/py3_raise.cpython-311.pyc +0 -0
  65. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/py3_raise.cpython-37.pyc +0 -0
  66. funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/py3_raise.cpython-39.pyc +0 -0
  67. funboost/utils/dependency_packages_in_pythonpath/func_timeout/dafunc.py +234 -234
  68. funboost/utils/dependency_packages_in_pythonpath/func_timeout/exceptions.py +98 -98
  69. funboost/utils/dependency_packages_in_pythonpath/func_timeout/py2_raise.py +7 -7
  70. funboost/utils/dependency_packages_in_pythonpath/func_timeout/py3_raise.py +7 -7
  71. funboost/utils/times/__init__.py +85 -85
  72. funboost/utils/times/version.py +1 -1
  73. {funboost-23.9.dist-info → funboost-24.2.dist-info}/METADATA +2 -1
  74. {funboost-23.9.dist-info → funboost-24.2.dist-info}/RECORD +77 -49
  75. {funboost-23.9.dist-info → funboost-24.2.dist-info}/WHEEL +5 -5
  76. funboost/utils/kill_thread.py +0 -113
  77. funboost/utils/show_funboost_flag.py +0 -28
  78. {funboost-23.9.dist-info → funboost-24.2.dist-info}/LICENSE +0 -0
  79. {funboost-23.9.dist-info → funboost-24.2.dist-info}/top_level.txt +0 -0
@@ -1,234 +1,234 @@
1
-
2
- # vim: set ts=4 sw=4 expandtab :
3
-
4
- '''
5
- Copyright (c) 2016, 2017 Tim Savannah All Rights Reserved.
6
-
7
- Licensed under the Lesser GNU Public License Version 3, LGPLv3. You should have recieved a copy of this with the source distribution as
8
- LICENSE, otherwise it is available at https://github.com/kata198/func_timeout/LICENSE
9
- '''
10
-
11
- import copy
12
- import inspect
13
- import threading
14
- import time
15
- import types
16
- import sys
17
-
18
- from .exceptions import FunctionTimedOut
19
- from .StoppableThread import StoppableThread
20
-
21
-
22
- from .py3_raise import raise_exception
23
-
24
-
25
- from functools import wraps
26
-
27
- __all__ = ('func_timeout', 'func_set_timeout')
28
-
29
-
30
- def func_timeout(timeout, func, args=(), kwargs=None):
31
- '''
32
- func_timeout - Runs the given function for up to #timeout# seconds.
33
-
34
- Raises any exceptions #func# would raise, returns what #func# would return (unless timeout is exceeded), in which case it raises FunctionTimedOut
35
-
36
- @param timeout <float> - Maximum number of seconds to run #func# before terminating
37
-
38
- @param func <function> - The function to call
39
-
40
- @param args <tuple> - Any ordered arguments to pass to the function
41
-
42
- @param kwargs <dict/None> - Keyword arguments to pass to the function.
43
-
44
-
45
- @raises - FunctionTimedOut if #timeout# is exceeded, otherwise anything #func# could raise will be raised
46
-
47
- If the timeout is exceeded, FunctionTimedOut will be raised within the context of the called function every two seconds until it terminates,
48
- but will not block the calling thread (a new thread will be created to perform the join). If possible, you should try/except FunctionTimedOut
49
- to return cleanly, but in most cases it will 'just work'.
50
-
51
- @return - The return value that #func# gives
52
- '''
53
-
54
- if not kwargs:
55
- kwargs = {}
56
- if not args:
57
- args = ()
58
-
59
- ret = []
60
- exception = []
61
- isStopped = False
62
-
63
- def funcwrap(args2, kwargs2):
64
- try:
65
- ret.append( func(*args2, **kwargs2) )
66
- except FunctionTimedOut:
67
- # Don't print traceback to stderr if we time out
68
- pass
69
- except BaseException as e:
70
- exc_info = sys.exc_info()
71
- if isStopped is False:
72
- # Assemble the alternate traceback, excluding this function
73
- # from the trace (by going to next frame)
74
- # Pytohn3 reads native from __traceback__,
75
- # python2 has a different form for "raise"
76
- e.__traceback__ = exc_info[2].tb_next
77
- exception.append( e )
78
-
79
- thread = StoppableThread(target=funcwrap, args=(args, kwargs))
80
- thread.daemon = True
81
-
82
- thread.start()
83
- thread.join(timeout)
84
-
85
- stopException = None
86
- if thread.is_alive():
87
- isStopped = True
88
-
89
- class FunctionTimedOutTempType(FunctionTimedOut):
90
- def __init__(self):
91
- return FunctionTimedOut.__init__(self, '', timeout, func, args, kwargs)
92
-
93
- FunctionTimedOutTemp = type('FunctionTimedOut' + str( hash( "%d_%d_%d_%d" %(id(timeout), id(func), id(args), id(kwargs))) ), FunctionTimedOutTempType.__bases__, dict(FunctionTimedOutTempType.__dict__))
94
-
95
- stopException = FunctionTimedOutTemp
96
- # raise FunctionTimedOut('', timeout, func, args, kwargs)
97
- thread._stopThread(stopException)
98
- thread.join(min(.1, timeout / 50.0))
99
- raise FunctionTimedOut('', timeout, func, args, kwargs)
100
- else:
101
- # We can still cleanup the thread here..
102
- # Still give a timeout... just... cuz..
103
- thread.join(.5)
104
-
105
- if exception:
106
- raise_exception(exception)
107
-
108
- if ret:
109
- return ret[0]
110
-
111
-
112
- def func_set_timeout(timeout, allowOverride=False):
113
- '''
114
- func_set_timeout - Decorator to run a function with a given/calculated timeout (max execution time).
115
- Optionally (if #allowOverride is True), adds a paramater, "forceTimeout", to the
116
- function which, if provided, will override the default timeout for that invocation.
117
-
118
- If #timeout is provided as a lambda/function, it will be called
119
- prior to each invocation of the decorated function to calculate the timeout to be used
120
- for that call, based on the arguments passed to the decorated function.
121
-
122
- For example, you may have a "processData" function whose execution time
123
- depends on the number of "data" elements, so you may want a million elements to have a
124
- much higher timeout than seven elements.)
125
-
126
- If #allowOverride is True AND a kwarg of "forceTimeout" is passed to the wrapped function, that timeout
127
- will be used for that single call.
128
-
129
- @param timeout <float OR lambda/function> -
130
-
131
- **If float:**
132
- Default number of seconds max to allow function to execute
133
- before throwing FunctionTimedOut
134
-
135
- **If lambda/function:
136
-
137
- If a function/lambda is provided, it will be called for every
138
- invocation of the decorated function (unless #allowOverride=True and "forceTimeout" was passed)
139
- to determine the timeout to use based on the arguments to the decorated function.
140
-
141
- The arguments as passed into the decorated function will be passed to this function.
142
- They either must match exactly to what the decorated function has, OR
143
- if you prefer to get the *args (list of ordered args) and **kwargs ( key : value keyword args form),
144
- define your calculate function like:
145
-
146
- def calculateTimeout(*args, **kwargs):
147
- ...
148
-
149
- or lambda like:
150
-
151
- calculateTimeout = lambda *args, **kwargs : ...
152
-
153
- otherwise the args to your calculate function should match exactly the decorated function.
154
-
155
-
156
- @param allowOverride <bool> Default False, if True adds a keyword argument to the decorated function,
157
- "forceTimeout" which, if provided, will override the #timeout. If #timeout was provided as a lambda / function, it
158
- will not be called.
159
-
160
- @throws FunctionTimedOut If time alloted passes without function returning naturally
161
-
162
- @see func_timeout
163
- '''
164
- # Try to be as efficent as possible... don't compare the args more than once
165
-
166
- # Helps closure issue on some versions of python
167
- defaultTimeout = copy.copy(timeout)
168
-
169
- isTimeoutAFunction = bool( issubclass(timeout.__class__, (types.FunctionType, types.MethodType, types.LambdaType, types.BuiltinFunctionType, types.BuiltinMethodType) ) )
170
-
171
- if not isTimeoutAFunction:
172
- if not issubclass(timeout.__class__, (float, int)):
173
- try:
174
- timeout = float(timeout)
175
- except:
176
- raise ValueError('timeout argument must be a float/int for number of seconds, or a function/lambda which gets passed the function arguments and returns a calculated timeout (as float or int). Passed type: < %s > is not of any of these, and cannot be converted to a float.' %( timeout.__class__.__name__, ))
177
-
178
-
179
- if not allowOverride and not isTimeoutAFunction:
180
- # Only defaultTimeout provided. Simple function wrapper
181
- def _function_decorator(func):
182
-
183
- return wraps(func)(lambda *args, **kwargs : func_timeout(defaultTimeout, func, args=args, kwargs=kwargs))
184
-
185
- # def _function_wrapper(*args, **kwargs):
186
- # return func_timeout(defaultTimeout, func, args=args, kwargs=kwargs)
187
- # return _function_wrapper
188
- return _function_decorator
189
-
190
- if not isTimeoutAFunction:
191
- # allowOverride is True and timeout is not a function. Simple conditional on every call
192
- def _function_decorator(func):
193
- def _function_wrapper(*args, **kwargs):
194
- if 'forceTimeout' in kwargs:
195
- useTimeout = kwargs.pop('forceTimeout')
196
- else:
197
- useTimeout = defaultTimeout
198
-
199
- return func_timeout(useTimeout, func, args=args, kwargs=kwargs)
200
-
201
- return wraps(func)(_function_wrapper)
202
- return _function_decorator
203
-
204
-
205
- # At this point, timeout IS known to be a function.
206
- timeoutFunction = timeout
207
-
208
- if allowOverride:
209
- # Could use a lambda here... but want traceback to highlight the calculate function,
210
- # and not the invoked function
211
- def _function_decorator(func):
212
- def _function_wrapper(*args, **kwargs):
213
- if 'forceTimeout' in kwargs:
214
- useTimeout = kwargs.pop('forceTimeout')
215
- else:
216
- useTimeout = timeoutFunction(*args, **kwargs)
217
-
218
- return func_timeout(useTimeout, func, args=args, kwargs=kwargs)
219
-
220
- return wraps(func)(_function_wrapper)
221
- return _function_decorator
222
-
223
- # Cannot override, and calculate timeout function
224
- def _function_decorator(func):
225
- def _function_wrapper(*args, **kwargs):
226
- useTimeout = timeoutFunction(*args, **kwargs)
227
-
228
- return func_timeout(useTimeout, func, args=args, kwargs=kwargs)
229
-
230
- return wraps(func)(_function_wrapper)
231
- return _function_decorator
232
-
233
-
234
- # vim: set ts=4 sw=4 expandtab :
1
+
2
+ # vim: set ts=4 sw=4 expandtab :
3
+
4
+ '''
5
+ Copyright (c) 2016, 2017 Tim Savannah All Rights Reserved.
6
+
7
+ Licensed under the Lesser GNU Public License Version 3, LGPLv3. You should have recieved a copy of this with the source distribution as
8
+ LICENSE, otherwise it is available at https://github.com/kata198/func_timeout/LICENSE
9
+ '''
10
+
11
+ import copy
12
+ import inspect
13
+ import threading
14
+ import time
15
+ import types
16
+ import sys
17
+
18
+ from .exceptions import FunctionTimedOut
19
+ from .StoppableThread import StoppableThread
20
+
21
+
22
+ from .py3_raise import raise_exception
23
+
24
+
25
+ from functools import wraps
26
+
27
+ __all__ = ('func_timeout', 'func_set_timeout')
28
+
29
+
30
+ def func_timeout(timeout, func, args=(), kwargs=None):
31
+ '''
32
+ func_timeout - Runs the given function for up to #timeout# seconds.
33
+
34
+ Raises any exceptions #func# would raise, returns what #func# would return (unless timeout is exceeded), in which case it raises FunctionTimedOut
35
+
36
+ @param timeout <float> - Maximum number of seconds to run #func# before terminating
37
+
38
+ @param func <function> - The function to call
39
+
40
+ @param args <tuple> - Any ordered arguments to pass to the function
41
+
42
+ @param kwargs <dict/None> - Keyword arguments to pass to the function.
43
+
44
+
45
+ @raises - FunctionTimedOut if #timeout# is exceeded, otherwise anything #func# could raise will be raised
46
+
47
+ If the timeout is exceeded, FunctionTimedOut will be raised within the context of the called function every two seconds until it terminates,
48
+ but will not block the calling thread (a new thread will be created to perform the join). If possible, you should try/except FunctionTimedOut
49
+ to return cleanly, but in most cases it will 'just work'.
50
+
51
+ @return - The return value that #func# gives
52
+ '''
53
+
54
+ if not kwargs:
55
+ kwargs = {}
56
+ if not args:
57
+ args = ()
58
+
59
+ ret = []
60
+ exception = []
61
+ isStopped = False
62
+
63
+ def funcwrap(args2, kwargs2):
64
+ try:
65
+ ret.append( func(*args2, **kwargs2) )
66
+ except FunctionTimedOut:
67
+ # Don't print traceback to stderr if we time out
68
+ pass
69
+ except BaseException as e:
70
+ exc_info = sys.exc_info()
71
+ if isStopped is False:
72
+ # Assemble the alternate traceback, excluding this function
73
+ # from the trace (by going to next frame)
74
+ # Pytohn3 reads native from __traceback__,
75
+ # python2 has a different form for "raise"
76
+ e.__traceback__ = exc_info[2].tb_next
77
+ exception.append( e )
78
+
79
+ thread = StoppableThread(target=funcwrap, args=(args, kwargs))
80
+ thread.daemon = True
81
+
82
+ thread.start()
83
+ thread.join(timeout)
84
+
85
+ stopException = None
86
+ if thread.is_alive():
87
+ isStopped = True
88
+
89
+ class FunctionTimedOutTempType(FunctionTimedOut):
90
+ def __init__(self):
91
+ return FunctionTimedOut.__init__(self, '', timeout, func, args, kwargs)
92
+
93
+ FunctionTimedOutTemp = type('FunctionTimedOut' + str( hash( "%d_%d_%d_%d" %(id(timeout), id(func), id(args), id(kwargs))) ), FunctionTimedOutTempType.__bases__, dict(FunctionTimedOutTempType.__dict__))
94
+
95
+ stopException = FunctionTimedOutTemp
96
+ # raise FunctionTimedOut('', timeout, func, args, kwargs)
97
+ thread._stopThread(stopException)
98
+ thread.join(min(.1, timeout / 50.0))
99
+ raise FunctionTimedOut('', timeout, func, args, kwargs)
100
+ else:
101
+ # We can still cleanup the thread here..
102
+ # Still give a timeout... just... cuz..
103
+ thread.join(.5)
104
+
105
+ if exception:
106
+ raise_exception(exception)
107
+
108
+ if ret:
109
+ return ret[0]
110
+
111
+
112
+ def func_set_timeout(timeout, allowOverride=False):
113
+ '''
114
+ func_set_timeout - Decorator to run a function with a given/calculated timeout (max execution time).
115
+ Optionally (if #allowOverride is True), adds a paramater, "forceTimeout", to the
116
+ function which, if provided, will override the default timeout for that invocation.
117
+
118
+ If #timeout is provided as a lambda/function, it will be called
119
+ prior to each invocation of the decorated function to calculate the timeout to be used
120
+ for that call, based on the arguments passed to the decorated function.
121
+
122
+ For example, you may have a "processData" function whose execution time
123
+ depends on the number of "data" elements, so you may want a million elements to have a
124
+ much higher timeout than seven elements.)
125
+
126
+ If #allowOverride is True AND a kwarg of "forceTimeout" is passed to the wrapped function, that timeout
127
+ will be used for that single call.
128
+
129
+ @param timeout <float OR lambda/function> -
130
+
131
+ **If float:**
132
+ Default number of seconds max to allow function to execute
133
+ before throwing FunctionTimedOut
134
+
135
+ **If lambda/function:
136
+
137
+ If a function/lambda is provided, it will be called for every
138
+ invocation of the decorated function (unless #allowOverride=True and "forceTimeout" was passed)
139
+ to determine the timeout to use based on the arguments to the decorated function.
140
+
141
+ The arguments as passed into the decorated function will be passed to this function.
142
+ They either must match exactly to what the decorated function has, OR
143
+ if you prefer to get the *args (list of ordered args) and **kwargs ( key : value keyword args form),
144
+ define your calculate function like:
145
+
146
+ def calculateTimeout(*args, **kwargs):
147
+ ...
148
+
149
+ or lambda like:
150
+
151
+ calculateTimeout = lambda *args, **kwargs : ...
152
+
153
+ otherwise the args to your calculate function should match exactly the decorated function.
154
+
155
+
156
+ @param allowOverride <bool> Default False, if True adds a keyword argument to the decorated function,
157
+ "forceTimeout" which, if provided, will override the #timeout. If #timeout was provided as a lambda / function, it
158
+ will not be called.
159
+
160
+ @throws FunctionTimedOut If time alloted passes without function returning naturally
161
+
162
+ @see func_timeout
163
+ '''
164
+ # Try to be as efficent as possible... don't compare the args more than once
165
+
166
+ # Helps closure issue on some versions of python
167
+ defaultTimeout = copy.copy(timeout)
168
+
169
+ isTimeoutAFunction = bool( issubclass(timeout.__class__, (types.FunctionType, types.MethodType, types.LambdaType, types.BuiltinFunctionType, types.BuiltinMethodType) ) )
170
+
171
+ if not isTimeoutAFunction:
172
+ if not issubclass(timeout.__class__, (float, int)):
173
+ try:
174
+ timeout = float(timeout)
175
+ except:
176
+ raise ValueError('timeout argument must be a float/int for number of seconds, or a function/lambda which gets passed the function arguments and returns a calculated timeout (as float or int). Passed type: < %s > is not of any of these, and cannot be converted to a float.' %( timeout.__class__.__name__, ))
177
+
178
+
179
+ if not allowOverride and not isTimeoutAFunction:
180
+ # Only defaultTimeout provided. Simple function wrapper
181
+ def _function_decorator(func):
182
+
183
+ return wraps(func)(lambda *args, **kwargs : func_timeout(defaultTimeout, func, args=args, kwargs=kwargs))
184
+
185
+ # def _function_wrapper(*args, **kwargs):
186
+ # return func_timeout(defaultTimeout, func, args=args, kwargs=kwargs)
187
+ # return _function_wrapper
188
+ return _function_decorator
189
+
190
+ if not isTimeoutAFunction:
191
+ # allowOverride is True and timeout is not a function. Simple conditional on every call
192
+ def _function_decorator(func):
193
+ def _function_wrapper(*args, **kwargs):
194
+ if 'forceTimeout' in kwargs:
195
+ useTimeout = kwargs.pop('forceTimeout')
196
+ else:
197
+ useTimeout = defaultTimeout
198
+
199
+ return func_timeout(useTimeout, func, args=args, kwargs=kwargs)
200
+
201
+ return wraps(func)(_function_wrapper)
202
+ return _function_decorator
203
+
204
+
205
+ # At this point, timeout IS known to be a function.
206
+ timeoutFunction = timeout
207
+
208
+ if allowOverride:
209
+ # Could use a lambda here... but want traceback to highlight the calculate function,
210
+ # and not the invoked function
211
+ def _function_decorator(func):
212
+ def _function_wrapper(*args, **kwargs):
213
+ if 'forceTimeout' in kwargs:
214
+ useTimeout = kwargs.pop('forceTimeout')
215
+ else:
216
+ useTimeout = timeoutFunction(*args, **kwargs)
217
+
218
+ return func_timeout(useTimeout, func, args=args, kwargs=kwargs)
219
+
220
+ return wraps(func)(_function_wrapper)
221
+ return _function_decorator
222
+
223
+ # Cannot override, and calculate timeout function
224
+ def _function_decorator(func):
225
+ def _function_wrapper(*args, **kwargs):
226
+ useTimeout = timeoutFunction(*args, **kwargs)
227
+
228
+ return func_timeout(useTimeout, func, args=args, kwargs=kwargs)
229
+
230
+ return wraps(func)(_function_wrapper)
231
+ return _function_decorator
232
+
233
+
234
+ # vim: set ts=4 sw=4 expandtab :