def test():
a=[2]
print(a[3])
def run():
test()
def err(error):
logger.exception(error)
if __name__ == '__main__':
pool = Pool(2)
t1 = pool.apply_async(run,error_callback=err)
pool.close()
pool.join()
日志记录 :
list index out of range
def test():
a=[2]
print(a[3])
def run():
test()
def err(error):
#这边已经拿到 error 了但是还要 try,要不然日志只记录 list index out of range
try:
raise error
except Exception as e:
logger.exception(e)
if __name__ == '__main__':
pool = Pool(2)
t1 = pool.apply_async(run,error_callback=err)
pool.close()
pool.join()
日志输出 :
list index out of range
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.5/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/home/work_dir/test/timer.py", line 13, in run
test()
File "/home/work_dir/test/timer.py", line 10, in test
print(a[3])
IndexError: list index out of range
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/work_dir/test/timer.py", line 17, in err
raise error
IndexError: list index out of range
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.