我用装饰器创建了一个库。它允许在单独的线程中无缝运行任何函数,并获得超时异常,即使由于IO破坏了NFS或其他令人讨厌的问题,该函数仍然停留在TASK_UNINTERRUPTIBLE中。
现在我正在处理异常处理。我将异常从线程传递回调用者线程并再次重新加载它。
现在跟踪(如果它在装饰函数内发生)看起来像这样:
Traceback (most recent call last):
File "1.py", line 11, in <module>
foo()
File "1.py", line 9, in foo
boo()
File "thread_timeout/__init__.py", line 116, in inner_worker
result = wrapped(*args, **kwargs)
File "1.py", line 6, in boo
file('/fdf','r')
如果我删除装饰器,它看起来像这样:
Traceback (most recent call last):
File "1.py", line 11, in <module>
foo()
File "1.py", line 9, in foo
boo()
File "1.py", line 6, in boo
file('/fdf','r')
IOError: [Errno 2] No such file or directory: '/fdf'
问题:我是否应该尝试隐藏装饰者的痕迹?
图书馆代码可在此处找到:https://github.com/amarao/thread_timeout/blob/master/thread_timeout/init.py
感谢。