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

Async exception handling #3731

Merged
merged 8 commits into from
Oct 8, 2016
Merged

Async exception handling #3731

merged 8 commits into from
Oct 8, 2016

Conversation

pvizeli
Copy link
Member

@pvizeli pvizeli commented Oct 6, 2016

Description:

Don't trow a exception on run_callback_threadsafe and run_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:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@mention-bot
Copy link

@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."""
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@pvizeli pvizeli added the async label Oct 6, 2016
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)
Copy link
Member

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)
Copy link
Member

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.

@pvizeli
Copy link
Member Author

pvizeli commented Oct 7, 2016

@balloob I think we now done with that. The error is not address to me on travis.

@balloob
Copy link
Member

balloob commented Oct 7, 2016

I think that it's ok. However would love to have @bbangert 👁 on it

@balloob
Copy link
Member

balloob commented Oct 7, 2016

If it's all good we should include it in release 30 as its confusing people

Copy link
Member

@bbangert bbangert left a comment

Choose a reason for hiding this comment

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

LGTM!

@balloob balloob merged commit f1e5d32 into home-assistant:dev Oct 8, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants