Fix Windows loop

This commit is contained in:
Paulus Schoutsen 2018-09-20 09:13:37 +02:00
parent fcb84d951e
commit cdaa7159d2
2 changed files with 12 additions and 11 deletions

View file

@ -19,15 +19,19 @@ from homeassistant.const import (
)
def attempt_use_uvloop() -> None:
def set_loop() -> None:
"""Attempt to use uvloop."""
import asyncio
try:
import uvloop
except ImportError:
pass
if sys.platform == 'win32':
asyncio.set_event_loop(asyncio.ProactorEventLoop())
else:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
try:
import uvloop
except ImportError:
pass
else:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
def validate_python() -> None:
@ -345,7 +349,7 @@ def main() -> int:
monkey_patch.disable_c_asyncio()
monkey_patch.patch_weakref_tasks()
attempt_use_uvloop()
set_loop()
args = get_arguments()

View file

@ -129,10 +129,7 @@ class HomeAssistant:
self,
loop: Optional[asyncio.events.AbstractEventLoop] = None) -> None:
"""Initialize new Home Assistant object."""
if sys.platform == 'win32':
self.loop = loop or asyncio.ProactorEventLoop()
else:
self.loop = loop or asyncio.get_event_loop()
self.loop = loop or asyncio.get_event_loop()
executor_opts = {'max_workers': None} # type: Dict[str, Any]
if sys.version_info[:2] >= (3, 6):