Fix ThreadResult not handling exceptions; remove apply_e. #556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using threadpools to do normal things like
.spawn
,.apply
etc worked significantly differently (erroneously) compared to other pools. Specifically, they would always swallow all exceptions: you'd get anAsyncResult
back that would say success and no value.The very strange
apply_e
wrapper attempted to work around this by wrapping functions in a try/catch that would return the result forapply_e
to re-raise. Except that all "non-expected" exceptions would be silently swallowed as successful. Thankfully(?) the only users of this usedException
andBaseException
.The correct thing is to store the exception for the AsyncResult to handle/raise/etc. as normal, which eliminates the weirdness and the danger of silently dropping exceptions.
To further clarify: by setting returning
False
fromThreadResult.successful
and settingThreadResult.exception
member, theAsyncResult
will correctly capture that exception to potentially reraise on a.get
if necessary.