From fd0260fc05fb005ed7c28b67d15e412188b849c3 Mon Sep 17 00:00:00 2001 From: Tim Savannah Date: Wed, 24 May 2017 01:32:55 -0400 Subject: [PATCH] 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+) --- func_timeout/dafunc.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/func_timeout/dafunc.py b/func_timeout/dafunc.py index 4e9dbb5..4debe6a 100644 --- a/func_timeout/dafunc.py +++ b/func_timeout/dafunc.py @@ -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]