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

Fix exception handling #199

Merged
merged 9 commits into from
Jun 28, 2018
Merged

Fix exception handling #199

merged 9 commits into from
Jun 28, 2018

Conversation

dirk-thomas
Copy link
Member

Fixes #198.

Looking for feedback on this patch.

@dirk-thomas dirk-thomas added bug Something isn't working in progress Actively being worked on (Kanban column) labels Jun 28, 2018
@dirk-thomas dirk-thomas self-assigned this Jun 28, 2018
if not self._done:
raise Error
if self._exception is not None:
raise self._exception
Copy link
Member Author

Choose a reason for hiding this comment

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

This is following the logic of the asyncio future.

@@ -55,8 +55,6 @@ def unblock(future):
future.add_done_callback(unblock)

event.wait()
if future.exception() is not None:
raise future.exception()
Copy link
Member Author

Choose a reason for hiding this comment

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

With the change to result() this is not necessary anymore since it happens implicitly.

self._executor.submit(handler)
future = self._executor.submit(handler)
# currently the future is been waited on?
# the result needs to be checked in order to re-raise potential exceptions
Copy link
Member Author

Choose a reason for hiding this comment

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

What should happen here?

@dirk-thomas dirk-thomas force-pushed the fix_exception_handling branch 3 times, most recently from 55169ce to ab1ea62 Compare June 28, 2018 17:00
@dirk-thomas dirk-thomas added in review Waiting for review (Kanban column) in progress Actively being worked on (Kanban column) and removed in progress Actively being worked on (Kanban column) in review Waiting for review (Kanban column) labels Jun 28, 2018
@dirk-thomas
Copy link
Member Author

We can't check for done in result() (see 8b9fe32) since result is now being called after a spin_once(). A coroutines which yields won't be finished after a single spin though.

This should at least pass our tests now. Back in review.

@dirk-thomas dirk-thomas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 28, 2018
@dirk-thomas dirk-thomas added this to the bouncy milestone Jun 28, 2018
@dirk-thomas
Copy link
Member Author

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@@ -42,6 +44,12 @@ def __init__(self, *, executor=None):
self._executor = None
self._set_executor(executor)

def __del__(self):
if self._exception is not None:
Copy link
Member

Choose a reason for hiding this comment

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

This will print even for exceptions that were retrieved, is that intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is correct. Unfortunately I don't see a way to avoid that since there is no API calling code invoked to "take" an exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a boolean flag. When exception() is being called it won't be reported assuming the caller did "the right thing" already.

raise CancelledError
# a coroutine might not have finished after calling spin_once
# if not self._done:
# raise Error
Copy link
Member

Choose a reason for hiding this comment

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

Is this the right behavior? I believe that in the other Future's Python provides, calling result before being set is an error (you should check if it is done first).

If calling result prematurely is an issue, and we only care about whether or not there was an exception, why not just do something like this in the executors:

if future.exception() is not None:
    raise future.exception()

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this the right behavior?

This is the current behavior of our coroutines / spinning them. The commented code is what Python's future class does but we can't enforce that at the moment.

why not just do something like this in the executors

We can do that instead. We don't even have to change the result() method at all for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed all the checking from result() for now. We should revisit this though after the release (see follow up ticket #200).

@dirk-thomas
Copy link
Member Author

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@@ -42,6 +44,12 @@ def __init__(self, *, executor=None):
self._executor = None
self._set_executor(executor)

def __del__(self):
if self._exception is not None and self._exception_fetched:
Copy link
Member

Choose a reason for hiding this comment

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

and not self._exception_fetched?

Copy link
Member Author

Choose a reason for hiding this comment

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

Very good point. I changed the logic to match the naming of the
variable: c63e3be

@dirk-thomas dirk-thomas mentioned this pull request Jun 28, 2018
@dirk-thomas dirk-thomas merged commit bdd994b into master Jun 28, 2018
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Jun 28, 2018
@dirk-thomas dirk-thomas deleted the fix_exception_handling branch June 28, 2018 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants