Remove usage of "run_until_complete"#16617
Conversation
homeassistant/helpers/signal.py
Outdated
There was a problem hiding this comment.
line too long (88 > 79 characters)
homeassistant/core.py
Outdated
There was a problem hiding this comment.
line too long (83 > 79 characters)
* Use asyncio.run (or our own implementation on Python <3.7) * hass.start is only used by tests * setup_and_run_hass() is now async * Add "main" async hass.run method * move SIGINT handling to helpers/signal.py * add flag to .run to disable hass's signal handlers * Teach async_start and async_stop to not step on each other (more than necessary)
|
|
||
| def attempt_use_uvloop() -> None: | ||
| """Attempt to use uvloop.""" | ||
| import asyncio |
There was a problem hiding this comment.
Ugh. Me being blind. Will fix.
homeassistant/core.py
Outdated
| if self.state == CoreState.not_running: # just ignore | ||
| return | ||
| if self.state == CoreState.stopping: | ||
| _LOGGER.info("async_stop called twice: ignored") |
There was a problem hiding this comment.
Might be a better idea. Will change.
homeassistant/util/__init__.py
Outdated
| } | ||
|
|
||
|
|
||
| try: |
There was a problem hiding this comment.
Can we move this to util.async_
| * queue shutdown code | ||
| * re-instate default handler | ||
| """ | ||
| hass.loop.remove_signal_handler(signal.SIGTERM) |
There was a problem hiding this comment.
Because the signal handler has initiated an orderly shutdown. Its job is now done; if we get the signal again, the user is impatient / the main loop is stuck, and standard Python signal handling should take over.
homeassistant/util/async_.py
Outdated
homeassistant/util/async_.py
Outdated
homeassistant/core.py
Outdated
There was a problem hiding this comment.
line too long (83 > 79 characters)
only useful for testing
Required for keeping requirements_test_all.txt in sync, where it is in turn required to prevent auto-downgrading "attrs" during "pip install"
homeassistant/util/async_.py
Outdated
|
Current tests break with undefined "mock_signal" fixture. |
|
Meh. Finally. (Had a broken local installation.) |
homeassistant/core.py
Outdated
| self.loop.close() | ||
| return self.exit_code | ||
|
|
||
| async def run(self, *, attach_signals: bool = True) -> int: |
There was a problem hiding this comment.
If this is an async method, we should call it async_run to be in line with the rest of our functions.
There was a problem hiding this comment.
My rationale for not naming it async_run is that it's never called from within Home Assistant, but I'll change it if you want me to, no problem.
requirements_test.txt
Outdated
| # make new things fail. Manually update these pins when pulling in a | ||
| # new version | ||
| asynctest==0.12.2 | ||
| attrs==18.2.0 |
There was a problem hiding this comment.
This shouldn't be necessary, it's already part of the core dependencies.
There was a problem hiding this comment.
The problem: when I do a pip install -r requirements_test_all.txt without this entry, attrs is downgraded to some lower version, probably because of some sub-module's requirements.
There was a problem hiding this comment.
Use the constraints file like Tox does: pip install -r requirements_test_all.txt -c homeassistant/package_constraints.txt
solved by using "pip -c"
balloob
left a comment
There was a problem hiding this comment.
ok to merge after run renamed to async_run
|
All done, please merge. |
|
Did it tested on Windows? I run on Windows Python 3.6.3 got some errors |
|
This logic should be moved to main to fix it: |
|
This should do it: #16737 |
Description:
This patch changes Home Assistant's startup routine so that it will run under
asyncio.run. It also changes the SIGINT handler to start the shutdown sequence.Advantages:
Disadvantages:
Checklist:
tox. Your PR cannot be merged unless tests pass