Change to using clever import strategy such that we dont have to use exec/eval
This commit is contained in:
parent
76cf4f6456
commit
9e1ac2fb8c
@ -18,6 +18,13 @@ import sys
|
|||||||
from .exceptions import FunctionTimedOut
|
from .exceptions import FunctionTimedOut
|
||||||
from .StoppableThread import StoppableThread
|
from .StoppableThread import StoppableThread
|
||||||
|
|
||||||
|
try:
|
||||||
|
from .py3_raise import raise_exception
|
||||||
|
except SyntaxError:
|
||||||
|
from .py2_raise import raise_exception
|
||||||
|
except ImportError:
|
||||||
|
from .py2_raise import raise_exception
|
||||||
|
|
||||||
__all__ = ('func_timeout', 'func_set_timeout')
|
__all__ = ('func_timeout', 'func_set_timeout')
|
||||||
|
|
||||||
|
|
||||||
@ -96,15 +103,7 @@ def func_timeout(timeout, func, args=(), kwargs=None):
|
|||||||
thread.join(.5)
|
thread.join(.5)
|
||||||
|
|
||||||
if exception:
|
if exception:
|
||||||
if sys.version_info >= (3, 3):
|
raise_exception(exception)
|
||||||
# PEP 409 - Raise with the chained exception context disabled
|
|
||||||
# This, in effect, prevents the "funcwrap" wrapper ( chained
|
|
||||||
# in context to an exception raised here, due to scope )
|
|
||||||
# Only available in python3.3+
|
|
||||||
exec('raise exception[0] from None', None, { 'exception' : exception, })
|
|
||||||
else:
|
|
||||||
# Python2 allows specifying an alternate traceback.
|
|
||||||
exec('raise exception[0] , None, exception[0].__traceback__', None, {'exception' : exception})
|
|
||||||
|
|
||||||
if ret:
|
if ret:
|
||||||
return ret[0]
|
return ret[0]
|
||||||
|
|||||||
5
func_timeout/py2_raise.py
Normal file
5
func_timeout/py2_raise.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# Python2 allows specifying an alternate traceback.
|
||||||
|
def raise_exception(exception):
|
||||||
|
raise exception[0] , None , exception[0].__traceback__
|
||||||
7
func_timeout/py3_raise.py
Normal file
7
func_timeout/py3_raise.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
# PEP 409 - Raise with the chained exception context disabled
|
||||||
|
# This, in effect, prevents the "funcwrap" wrapper ( chained
|
||||||
|
# in context to an exception raised here, due to scope )
|
||||||
|
# Only available in python3.3+
|
||||||
|
def raise_exception(exception):
|
||||||
|
raise exception[0] from None
|
||||||
Loading…
Reference in New Issue
Block a user