For python >= 3.3, raise with the chained exception context disabled, since the funcwrap wrapper is within the context where the exception would be thrown (on python3+)

This commit is contained in:
Tim Savannah 2017-05-24 01:32:55 -04:00
parent 3275780482
commit fd0260fc05

View File

@ -13,6 +13,7 @@ import inspect
import threading
import time
import types
import sys
from .exceptions import FunctionTimedOut
from .StoppableThread import StoppableThread
@ -90,7 +91,14 @@ def func_timeout(timeout, func, args=(), kwargs=None):
thread.join(.5)
if exception:
raise exception[0]
if sys.version_info >= (3, 3):
# 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:
raise exception[0]
if ret:
return ret[0]