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