-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Async exception handling #3731
Async exception handling #3731
Conversation
@pvizeli, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabianhjr and @jaharkes to be potential reviewers. |
@@ -318,6 +319,14 @@ def async_stop(self) -> None: | |||
self.state = CoreState.not_running | |||
self.loop.stop() | |||
|
|||
# pylint: disable=no-self-use | |||
def _async_exception_handler(self, loop, context): | |||
"""Handle all exception inside the core loop.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a debug here that also includes the exception?
https://github.com/python/asyncio/blob/master/asyncio/base_events.py#L1195
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
except Exception as exc: | ||
if future.set_running_or_notify_cancel(): | ||
future.set_exception(exc) | ||
raise | ||
else: | ||
_LOGGER.warning("Exception on lost future: %s", exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exc_info=True
instead of putting the exception object in the log string.
except Exception as exc: | ||
if future.set_running_or_notify_cancel(): | ||
future.set_exception(exc) | ||
raise | ||
else: | ||
_LOGGER.warning("Exception on lost future: %s", exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exc_info=True instead of putting the exception object in the log string.
@balloob I think we now done with that. The error is not address to me on travis. |
I think that it's ok. However would love to have @bbangert 👁 on it |
If it's all good we should include it in release 30 as its confusing people |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description:
Don't trow a exception on
run_callback_threadsafe
andrun_coroutine_threadsafe
. It save that to Future if a process is waiting to or it make a warning to log for developer that he know that it make a misstake.Add a own exception handler to async loop and print a warning if exception is catch on loop. In debug mode it print a trace. So have the user only a message and not a lot uf stuff who are not understund. This ignore also message like "exception was never retrieved" and protect the async loop.
CC @balloob @bbangert
If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass