-
-
Notifications
You must be signed in to change notification settings - Fork 89
Closed
Labels
Milestone
Description
I was trying to a proper traceback and I think I encountered any error.
In this code, I create a div0 error and print it out in the parent thread.
# from pathos.pools import ThreadPool as ProcessPool
from pathos.pools import ProcessPool as ProcessPool
def function(x):
return 1/x
def errorReturnWrapper(func,
printTraceback = False):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except KeyboardInterrupt:
print("Worker got keyboard interrupt somehow")
except Exception as e:
import traceback
error = str(e)
tb = traceback.format_exc()
return type(e)(f"{e}\n\nOriginal {tb}")
return wrapper
if __name__ == "__main__":
pool = ProcessPool(nodes = 1)
results = pool.map(errorReturnWrapper(function), [0,1,2,3,4])
print(results[0])
The error is as expected with ThreadPool:
division by zero
Original Traceback (most recent call last):
File "**redacted**\exception.py", line 11, in wrapper
return func(*args, **kwargs)
File "**redacted**\exception.py", line 5, in function
return 1/x
ZeroDivisionError: division by zero
But offset by 1 line with ProcessPool:
Original Traceback (most recent call last):
File "**redacted**\exception.py", line 12, in wrapper
except KeyboardInterrupt:
File "**redacted**\exception.py", line -13, in function
ZeroDivisionError: division by zero```
Reactions are currently unavailable