Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore exceptions raised in user created tasks #1395

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from

Conversation

nadavelkabets
Copy link
Contributor

@nadavelkabets nadavelkabets commented Jan 4, 2025

Addresses #1098.
Currently exceptions raised in user created tasks crash the executor. In my project I had to catch the exception and return it to allow communicating exceptions from the task to the main code.
This pull request mimics the behavior of asyncio, in which exceptions in tasks are ignored and logged upon garbage collection.
The logging part is already implemented, although this code is currently unreachable.
It was only necessary to add a line in the SingleThreadedExecutor to check if the task is related to an entity, since user created tasks are not bounded to any entity.

def __del__(self) -> None:
if self._exception is not None and not self._exception_fetched:
print(
'The following exception was never retrieved: ' + str(self._exception),
file=sys.stderr)

@fujitatomoya

Signed-off-by: = <elnadav12@gmail.com>
@apockill
Copy link
Contributor

apockill commented Jan 5, 2025

yes thank you for this. I ran into this and didn't know enough about the Task system to know if this was expected behavior, so I ended up wrapping my function in an exception catcher, then re-raising it after getting the future.

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but i would like to request other maintainers to review, test would be ideal.

CC: @sloretz @ahcorde

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants