Skip to content

Commit

Permalink
move run_asyncio to homeassistant.util.async_
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfix committed Sep 15, 2018
1 parent 0f0d5c2 commit 84ab2d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion homeassistant/__main__.py
Expand Up @@ -360,7 +360,7 @@ def main() -> int:
if args.pid_file:
write_pid(args.pid_file)

from homeassistant.util import asyncio_run
from homeassistant.util.async_ import asyncio_run
exit_code = asyncio_run(setup_and_run_hass(config_dir, args))
if exit_code == RESTART_EXIT_CODE and not args.runner:
try_to_restart()
Expand Down
9 changes: 0 additions & 9 deletions homeassistant/util/__init__.py
Expand Up @@ -30,15 +30,6 @@
}


try:
asyncio_run = asyncio.run
except AttributeError:
def asyncio_run(main, *, debug=False):
loop = asyncio.new_event_loop()
loop.set_debug(debug)
return loop.run(main)


def sanitize_filename(filename: str) -> str:
r"""Sanitize a filename by removing .. / and \\."""
return RE_SANITIZE_FILENAME.sub("", filename)
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/util/async_.py
Expand Up @@ -13,6 +13,15 @@
_LOGGER = logging.getLogger(__name__)


try:
asyncio_run = asyncio.run
except AttributeError:
def asyncio_run(main, *, debug=False):
loop = asyncio.new_event_loop()
loop.set_debug(debug)
return loop.run(main)


def _set_result_unless_cancelled(fut: Future, result: Any) -> None:
"""Set the result only if the Future was not cancelled."""
if fut.cancelled():
Expand Down

0 comments on commit 84ab2d9

Please sign in to comment.