funboost 44.3__py3-none-any.whl → 44.5__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.
- funboost/__init__.py +1 -1
- funboost/concurrent_pool/async_helper.py +3 -1
- funboost/constant.py +9 -10
- funboost/consumers/base_consumer.py +21 -22
- funboost/consumers/redis_consumer_ack_using_timeout.py +77 -0
- funboost/consumers/redis_consumer_simple.py +0 -1
- funboost/contrib/api_publish_msg.py +4 -3
- funboost/core/booster.py +17 -2
- funboost/core/funboost_time.py +26 -9
- funboost/core/helper_funs.py +16 -2
- funboost/core/lazy_impoter.py +1 -1
- funboost/core/loggers.py +3 -3
- funboost/factories/broker_kind__publsiher_consumer_type_map.py +3 -2
- funboost/funboost_config_deafult.py +1 -1
- funboost/function_result_web/__pycache__/functions.cpython-39.pyc +0 -0
- funboost/utils/decorators.py +1 -0
- funboost/utils/dependency_packages_in_pythonpath/__pycache__/__init__.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/__pycache__/add_to_pythonpath.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__init__.py +59 -59
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/__init__.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/client.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/compat.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/connection.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/exceptions.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/lock.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/utils.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/client.py +4804 -4804
- funboost/utils/dependency_packages_in_pythonpath/aioredis/compat.py +8 -8
- funboost/utils/dependency_packages_in_pythonpath/aioredis/connection.py +1668 -1668
- funboost/utils/dependency_packages_in_pythonpath/aioredis/exceptions.py +96 -96
- funboost/utils/dependency_packages_in_pythonpath/aioredis/lock.py +306 -306
- funboost/utils/dependency_packages_in_pythonpath/aioredis/log.py +15 -15
- funboost/utils/dependency_packages_in_pythonpath/aioredis/sentinel.py +329 -329
- funboost/utils/dependency_packages_in_pythonpath/aioredis/utils.py +61 -61
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/StoppableThread.py +133 -133
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__init__.py +16 -16
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/StoppableThread.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/__init__.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/dafunc.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/exceptions.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/py3_raise.cpython-39.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/dafunc.py +244 -244
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/exceptions.py +98 -98
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/py2_raise.py +7 -7
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/py3_raise.py +7 -7
- funboost/utils/json_helper.py +14 -1
- funboost/utils/times/__init__.py +85 -85
- funboost/utils/times/version.py +1 -1
- {funboost-44.3.dist-info → funboost-44.5.dist-info}/METADATA +9 -4
- {funboost-44.3.dist-info → funboost-44.5.dist-info}/RECORD +54 -82
- {funboost-44.3.dist-info → funboost-44.5.dist-info}/entry_points.txt +0 -1
- funboost/function_result_web/__pycache__/app.cpython-37.pyc +0 -0
- funboost/function_result_web/__pycache__/functions.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/__pycache__/__init__.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/__pycache__/__init__.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/__pycache__/add_to_pythonpath.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/__pycache__/add_to_pythonpath.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/__init__.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/__init__.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/client.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/client.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/compat.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/compat.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/connection.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/connection.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/exceptions.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/exceptions.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/lock.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/lock.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/utils.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/aioredis/__pycache__/utils.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/StoppableThread.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/StoppableThread.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/__init__.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/__init__.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/dafunc.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/dafunc.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/exceptions.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/exceptions.cpython-37.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/py3_raise.cpython-311.pyc +0 -0
- funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/py3_raise.cpython-37.pyc +0 -0
- {funboost-44.3.dist-info → funboost-44.5.dist-info}/LICENSE +0 -0
- {funboost-44.3.dist-info → funboost-44.5.dist-info}/WHEEL +0 -0
- {funboost-44.3.dist-info → funboost-44.5.dist-info}/top_level.txt +0 -0
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, TypeVar, overload
|
|
2
|
-
|
|
3
|
-
if TYPE_CHECKING:
|
|
4
|
-
from aioredis import Redis
|
|
5
|
-
from aioredis.client import Pipeline
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
try:
|
|
9
|
-
import hiredis # noqa
|
|
10
|
-
|
|
11
|
-
HIREDIS_AVAILABLE = True
|
|
12
|
-
except ImportError:
|
|
13
|
-
HIREDIS_AVAILABLE = False
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_T = TypeVar("_T")
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def from_url(url, **kwargs):
|
|
20
|
-
"""
|
|
21
|
-
Returns an active Redis client generated from the given database URL.
|
|
22
|
-
|
|
23
|
-
Will attempt to extract the database id from the path url fragment, if
|
|
24
|
-
none is provided.
|
|
25
|
-
"""
|
|
26
|
-
from aioredis.client import Redis
|
|
27
|
-
|
|
28
|
-
return Redis.from_url(url, **kwargs)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class pipeline:
|
|
32
|
-
def __init__(self, redis_obj: "Redis"):
|
|
33
|
-
self.p: "Pipeline" = redis_obj.pipeline()
|
|
34
|
-
|
|
35
|
-
async def __aenter__(self) -> "Pipeline":
|
|
36
|
-
return self.p
|
|
37
|
-
|
|
38
|
-
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
39
|
-
await self.p.execute()
|
|
40
|
-
del self.p
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
# Mypy bug: https://github.com/python/mypy/issues/11005
|
|
44
|
-
@overload
|
|
45
|
-
def str_if_bytes(value: bytes) -> str: # type: ignore[misc]
|
|
46
|
-
...
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@overload
|
|
50
|
-
def str_if_bytes(value: _T) -> _T:
|
|
51
|
-
...
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def str_if_bytes(value: object) -> object:
|
|
55
|
-
return (
|
|
56
|
-
value.decode("utf-8", errors="replace") if isinstance(value, bytes) else value
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def safe_str(value: object) -> str:
|
|
61
|
-
return str(str_if_bytes(value))
|
|
1
|
+
from typing import TYPE_CHECKING, TypeVar, overload
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from aioredis import Redis
|
|
5
|
+
from aioredis.client import Pipeline
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
import hiredis # noqa
|
|
10
|
+
|
|
11
|
+
HIREDIS_AVAILABLE = True
|
|
12
|
+
except ImportError:
|
|
13
|
+
HIREDIS_AVAILABLE = False
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
_T = TypeVar("_T")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def from_url(url, **kwargs):
|
|
20
|
+
"""
|
|
21
|
+
Returns an active Redis client generated from the given database URL.
|
|
22
|
+
|
|
23
|
+
Will attempt to extract the database id from the path url fragment, if
|
|
24
|
+
none is provided.
|
|
25
|
+
"""
|
|
26
|
+
from aioredis.client import Redis
|
|
27
|
+
|
|
28
|
+
return Redis.from_url(url, **kwargs)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class pipeline:
|
|
32
|
+
def __init__(self, redis_obj: "Redis"):
|
|
33
|
+
self.p: "Pipeline" = redis_obj.pipeline()
|
|
34
|
+
|
|
35
|
+
async def __aenter__(self) -> "Pipeline":
|
|
36
|
+
return self.p
|
|
37
|
+
|
|
38
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
39
|
+
await self.p.execute()
|
|
40
|
+
del self.p
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# Mypy bug: https://github.com/python/mypy/issues/11005
|
|
44
|
+
@overload
|
|
45
|
+
def str_if_bytes(value: bytes) -> str: # type: ignore[misc]
|
|
46
|
+
...
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@overload
|
|
50
|
+
def str_if_bytes(value: _T) -> _T:
|
|
51
|
+
...
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def str_if_bytes(value: object) -> object:
|
|
55
|
+
return (
|
|
56
|
+
value.decode("utf-8", errors="replace") if isinstance(value, bytes) else value
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def safe_str(value: object) -> str:
|
|
61
|
+
return str(str_if_bytes(value))
|
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Copyright (c) 2016, 2017, 2019 Timothy Savannah All Rights Reserved.
|
|
3
|
-
|
|
4
|
-
Licensed under the Lesser GNU Public License Version 3, LGPLv3. You should have recieved a copy of this with the source distribution as
|
|
5
|
-
LICENSE, otherwise it is available at https://github.com/kata198/func_timeout/LICENSE
|
|
6
|
-
'''
|
|
7
|
-
|
|
8
|
-
import os
|
|
9
|
-
import ctypes
|
|
10
|
-
import threading
|
|
11
|
-
|
|
12
|
-
__all__ = ('StoppableThread', 'JoinThread')
|
|
13
|
-
|
|
14
|
-
class StoppableThread(threading.Thread):
|
|
15
|
-
'''
|
|
16
|
-
StoppableThread - A thread that can be stopped by forcing an exception in the execution context.
|
|
17
|
-
|
|
18
|
-
This works both to interrupt code that is in C or in python code, at either the next call to a python function,
|
|
19
|
-
or the next line in python code.
|
|
20
|
-
|
|
21
|
-
It is recommended that if you call stop ( @see StoppableThread.stop ) that you use an exception that inherits BaseException, to ensure it likely isn't caught.
|
|
22
|
-
|
|
23
|
-
Also, beware unmarked exception handlers in your code. Code like this:
|
|
24
|
-
|
|
25
|
-
while True:
|
|
26
|
-
try:
|
|
27
|
-
doSomething()
|
|
28
|
-
except:
|
|
29
|
-
continue
|
|
30
|
-
|
|
31
|
-
will never be able to abort, because the exception you raise is immediately caught.
|
|
32
|
-
|
|
33
|
-
The exception is raised over and over, with a specifed delay (default 2.0 seconds)
|
|
34
|
-
'''
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def _stopThread(self, exception, raiseEvery=2.0):
|
|
38
|
-
'''
|
|
39
|
-
_stopThread - @see StoppableThread.stop
|
|
40
|
-
'''
|
|
41
|
-
if self.is_alive() is False:
|
|
42
|
-
return True
|
|
43
|
-
|
|
44
|
-
self._stderr = open(os.devnull, 'w')
|
|
45
|
-
|
|
46
|
-
# Create "joining" thread which will raise the provided exception
|
|
47
|
-
# on a repeat, until the thread stops.
|
|
48
|
-
joinThread = JoinThread(self, exception, repeatEvery=raiseEvery)
|
|
49
|
-
|
|
50
|
-
# Try to prevent spurrious prints
|
|
51
|
-
joinThread._stderr = self._stderr
|
|
52
|
-
joinThread.start()
|
|
53
|
-
joinThread._stderr = self._stderr
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def stop(self, exception, raiseEvery=2.0):
|
|
57
|
-
'''
|
|
58
|
-
Stops the thread by raising a given exception.
|
|
59
|
-
|
|
60
|
-
@param exception <Exception type> - Exception to throw. Likely, you want to use something
|
|
61
|
-
|
|
62
|
-
that inherits from BaseException (so except BaseException as e: continue; isn't a problem)
|
|
63
|
-
|
|
64
|
-
This should be a class/type, NOT an instance, i.e. MyExceptionType not MyExceptionType()
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
@param raiseEvery <float> Default 2.0 - We will keep raising this exception every #raiseEvery seconds,
|
|
68
|
-
|
|
69
|
-
until the thread terminates.
|
|
70
|
-
|
|
71
|
-
If your code traps a specific exception type, this will allow you #raiseEvery seconds to cleanup before exit.
|
|
72
|
-
|
|
73
|
-
If you're calling third-party code you can't control, which catches BaseException, set this to a low number
|
|
74
|
-
|
|
75
|
-
to break out of their exception handler.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
@return <None>
|
|
79
|
-
'''
|
|
80
|
-
return self._stopThread(exception, raiseEvery)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
class JoinThread(threading.Thread):
|
|
84
|
-
'''
|
|
85
|
-
JoinThread - The workhouse that stops the StoppableThread.
|
|
86
|
-
|
|
87
|
-
Takes an exception, and upon being started immediately raises that exception in the current context
|
|
88
|
-
of the thread's execution (so next line of python gets it, or next call to a python api function in C code ).
|
|
89
|
-
|
|
90
|
-
@see StoppableThread for more details
|
|
91
|
-
'''
|
|
92
|
-
|
|
93
|
-
def __init__(self, otherThread, exception, repeatEvery=2.0):
|
|
94
|
-
'''
|
|
95
|
-
__init__ - Create a JoinThread (don't forget to call .start() ! )
|
|
96
|
-
|
|
97
|
-
@param otherThread <threading.Thread> - A thread
|
|
98
|
-
|
|
99
|
-
@param exception <BaseException> - An exception. Should be a BaseException, to prevent "catch Exception as e: continue" type code
|
|
100
|
-
from never being terminated. If such code is unavoidable, you can try setting #repeatEvery to a very low number, like .00001,
|
|
101
|
-
and it will hopefully raise within the context of the catch, and be able to break free.
|
|
102
|
-
|
|
103
|
-
@param repeatEvery <float> Default 2.0 - After starting, the given exception is immediately raised. Then, every #repeatEvery seconds,
|
|
104
|
-
it is raised again, until the thread terminates.
|
|
105
|
-
'''
|
|
106
|
-
threading.Thread.__init__(self)
|
|
107
|
-
self.otherThread = otherThread
|
|
108
|
-
self.exception = exception
|
|
109
|
-
self.repeatEvery = repeatEvery
|
|
110
|
-
self.daemon = True
|
|
111
|
-
|
|
112
|
-
def run(self):
|
|
113
|
-
'''
|
|
114
|
-
run - The thread main. Will attempt to stop and join the attached thread.
|
|
115
|
-
'''
|
|
116
|
-
|
|
117
|
-
# Try to silence default exception printing.
|
|
118
|
-
self.otherThread._Thread__stderr = self._stderr
|
|
119
|
-
if hasattr(self.otherThread, '_Thread__stop'):
|
|
120
|
-
# If py2, call this first to start thread termination cleanly.
|
|
121
|
-
# Python3 does not need such ( nor does it provide.. )
|
|
122
|
-
self.otherThread._Thread__stop()
|
|
123
|
-
while self.otherThread.is_alive():
|
|
124
|
-
# We loop raising exception incase it's caught hopefully this breaks us far out.
|
|
125
|
-
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.otherThread.ident), ctypes.py_object(self.exception))
|
|
126
|
-
self.otherThread.join(self.repeatEvery)
|
|
127
|
-
|
|
128
|
-
try:
|
|
129
|
-
self._stderr.close()
|
|
130
|
-
except:
|
|
131
|
-
pass
|
|
132
|
-
|
|
133
|
-
# vim: set ts=4 sw=4 expandtab :
|
|
1
|
+
'''
|
|
2
|
+
Copyright (c) 2016, 2017, 2019 Timothy Savannah All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
Licensed under the Lesser GNU Public License Version 3, LGPLv3. You should have recieved a copy of this with the source distribution as
|
|
5
|
+
LICENSE, otherwise it is available at https://github.com/kata198/func_timeout/LICENSE
|
|
6
|
+
'''
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import ctypes
|
|
10
|
+
import threading
|
|
11
|
+
|
|
12
|
+
__all__ = ('StoppableThread', 'JoinThread')
|
|
13
|
+
|
|
14
|
+
class StoppableThread(threading.Thread):
|
|
15
|
+
'''
|
|
16
|
+
StoppableThread - A thread that can be stopped by forcing an exception in the execution context.
|
|
17
|
+
|
|
18
|
+
This works both to interrupt code that is in C or in python code, at either the next call to a python function,
|
|
19
|
+
or the next line in python code.
|
|
20
|
+
|
|
21
|
+
It is recommended that if you call stop ( @see StoppableThread.stop ) that you use an exception that inherits BaseException, to ensure it likely isn't caught.
|
|
22
|
+
|
|
23
|
+
Also, beware unmarked exception handlers in your code. Code like this:
|
|
24
|
+
|
|
25
|
+
while True:
|
|
26
|
+
try:
|
|
27
|
+
doSomething()
|
|
28
|
+
except:
|
|
29
|
+
continue
|
|
30
|
+
|
|
31
|
+
will never be able to abort, because the exception you raise is immediately caught.
|
|
32
|
+
|
|
33
|
+
The exception is raised over and over, with a specifed delay (default 2.0 seconds)
|
|
34
|
+
'''
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _stopThread(self, exception, raiseEvery=2.0):
|
|
38
|
+
'''
|
|
39
|
+
_stopThread - @see StoppableThread.stop
|
|
40
|
+
'''
|
|
41
|
+
if self.is_alive() is False:
|
|
42
|
+
return True
|
|
43
|
+
|
|
44
|
+
self._stderr = open(os.devnull, 'w')
|
|
45
|
+
|
|
46
|
+
# Create "joining" thread which will raise the provided exception
|
|
47
|
+
# on a repeat, until the thread stops.
|
|
48
|
+
joinThread = JoinThread(self, exception, repeatEvery=raiseEvery)
|
|
49
|
+
|
|
50
|
+
# Try to prevent spurrious prints
|
|
51
|
+
joinThread._stderr = self._stderr
|
|
52
|
+
joinThread.start()
|
|
53
|
+
joinThread._stderr = self._stderr
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def stop(self, exception, raiseEvery=2.0):
|
|
57
|
+
'''
|
|
58
|
+
Stops the thread by raising a given exception.
|
|
59
|
+
|
|
60
|
+
@param exception <Exception type> - Exception to throw. Likely, you want to use something
|
|
61
|
+
|
|
62
|
+
that inherits from BaseException (so except BaseException as e: continue; isn't a problem)
|
|
63
|
+
|
|
64
|
+
This should be a class/type, NOT an instance, i.e. MyExceptionType not MyExceptionType()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@param raiseEvery <float> Default 2.0 - We will keep raising this exception every #raiseEvery seconds,
|
|
68
|
+
|
|
69
|
+
until the thread terminates.
|
|
70
|
+
|
|
71
|
+
If your code traps a specific exception type, this will allow you #raiseEvery seconds to cleanup before exit.
|
|
72
|
+
|
|
73
|
+
If you're calling third-party code you can't control, which catches BaseException, set this to a low number
|
|
74
|
+
|
|
75
|
+
to break out of their exception handler.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@return <None>
|
|
79
|
+
'''
|
|
80
|
+
return self._stopThread(exception, raiseEvery)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class JoinThread(threading.Thread):
|
|
84
|
+
'''
|
|
85
|
+
JoinThread - The workhouse that stops the StoppableThread.
|
|
86
|
+
|
|
87
|
+
Takes an exception, and upon being started immediately raises that exception in the current context
|
|
88
|
+
of the thread's execution (so next line of python gets it, or next call to a python api function in C code ).
|
|
89
|
+
|
|
90
|
+
@see StoppableThread for more details
|
|
91
|
+
'''
|
|
92
|
+
|
|
93
|
+
def __init__(self, otherThread, exception, repeatEvery=2.0):
|
|
94
|
+
'''
|
|
95
|
+
__init__ - Create a JoinThread (don't forget to call .start() ! )
|
|
96
|
+
|
|
97
|
+
@param otherThread <threading.Thread> - A thread
|
|
98
|
+
|
|
99
|
+
@param exception <BaseException> - An exception. Should be a BaseException, to prevent "catch Exception as e: continue" type code
|
|
100
|
+
from never being terminated. If such code is unavoidable, you can try setting #repeatEvery to a very low number, like .00001,
|
|
101
|
+
and it will hopefully raise within the context of the catch, and be able to break free.
|
|
102
|
+
|
|
103
|
+
@param repeatEvery <float> Default 2.0 - After starting, the given exception is immediately raised. Then, every #repeatEvery seconds,
|
|
104
|
+
it is raised again, until the thread terminates.
|
|
105
|
+
'''
|
|
106
|
+
threading.Thread.__init__(self)
|
|
107
|
+
self.otherThread = otherThread
|
|
108
|
+
self.exception = exception
|
|
109
|
+
self.repeatEvery = repeatEvery
|
|
110
|
+
self.daemon = True
|
|
111
|
+
|
|
112
|
+
def run(self):
|
|
113
|
+
'''
|
|
114
|
+
run - The thread main. Will attempt to stop and join the attached thread.
|
|
115
|
+
'''
|
|
116
|
+
|
|
117
|
+
# Try to silence default exception printing.
|
|
118
|
+
self.otherThread._Thread__stderr = self._stderr
|
|
119
|
+
if hasattr(self.otherThread, '_Thread__stop'):
|
|
120
|
+
# If py2, call this first to start thread termination cleanly.
|
|
121
|
+
# Python3 does not need such ( nor does it provide.. )
|
|
122
|
+
self.otherThread._Thread__stop()
|
|
123
|
+
while self.otherThread.is_alive():
|
|
124
|
+
# We loop raising exception incase it's caught hopefully this breaks us far out.
|
|
125
|
+
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.otherThread.ident), ctypes.py_object(self.exception))
|
|
126
|
+
self.otherThread.join(self.repeatEvery)
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
self._stderr.close()
|
|
130
|
+
except:
|
|
131
|
+
pass
|
|
132
|
+
|
|
133
|
+
# vim: set ts=4 sw=4 expandtab :
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Copyright (c) 2016, 2017, 2019 Tim Savannah All Rights Reserved.
|
|
3
|
-
|
|
4
|
-
Licensed under the Lesser GNU Public License Version 3, LGPLv3. You should have recieved a copy of this with the source distribution as
|
|
5
|
-
LICENSE, otherwise it is available at https://github.com/kata198/func_timeout/LICENSE
|
|
6
|
-
'''
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
__version__ = '4.3.5'
|
|
10
|
-
__version_tuple__ = (4, 3, 5)
|
|
11
|
-
|
|
12
|
-
__all__ = ('func_timeout', 'func_set_timeout', 'FunctionTimedOut', 'StoppableThread')
|
|
13
|
-
|
|
14
|
-
from .exceptions import FunctionTimedOut
|
|
15
|
-
from .dafunc import func_timeout, func_set_timeout
|
|
16
|
-
from .StoppableThread import StoppableThread
|
|
1
|
+
'''
|
|
2
|
+
Copyright (c) 2016, 2017, 2019 Tim Savannah All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
Licensed under the Lesser GNU Public License Version 3, LGPLv3. You should have recieved a copy of this with the source distribution as
|
|
5
|
+
LICENSE, otherwise it is available at https://github.com/kata198/func_timeout/LICENSE
|
|
6
|
+
'''
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
__version__ = '4.3.5'
|
|
10
|
+
__version_tuple__ = (4, 3, 5)
|
|
11
|
+
|
|
12
|
+
__all__ = ('func_timeout', 'func_set_timeout', 'FunctionTimedOut', 'StoppableThread')
|
|
13
|
+
|
|
14
|
+
from .exceptions import FunctionTimedOut
|
|
15
|
+
from .dafunc import func_timeout, func_set_timeout
|
|
16
|
+
from .StoppableThread import StoppableThread
|
|
Binary file
|
funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/__init__.cpython-39.pyc
CHANGED
|
Binary file
|
funboost/utils/dependency_packages_in_pythonpath/func_timeout/__pycache__/dafunc.cpython-39.pyc
CHANGED
|
Binary file
|