Fix Windows loop
This commit is contained in:
parent
fcb84d951e
commit
cdaa7159d2
2 changed files with 12 additions and 11 deletions
|
@ -19,15 +19,19 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def attempt_use_uvloop() -> None:
|
def set_loop() -> None:
|
||||||
"""Attempt to use uvloop."""
|
"""Attempt to use uvloop."""
|
||||||
import asyncio
|
import asyncio
|
||||||
try:
|
|
||||||
import uvloop
|
if sys.platform == 'win32':
|
||||||
except ImportError:
|
asyncio.set_event_loop(asyncio.ProactorEventLoop())
|
||||||
pass
|
|
||||||
else:
|
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:
|
def validate_python() -> None:
|
||||||
|
@ -345,7 +349,7 @@ def main() -> int:
|
||||||
monkey_patch.disable_c_asyncio()
|
monkey_patch.disable_c_asyncio()
|
||||||
monkey_patch.patch_weakref_tasks()
|
monkey_patch.patch_weakref_tasks()
|
||||||
|
|
||||||
attempt_use_uvloop()
|
set_loop()
|
||||||
|
|
||||||
args = get_arguments()
|
args = get_arguments()
|
||||||
|
|
||||||
|
|
|
@ -129,10 +129,7 @@ class HomeAssistant:
|
||||||
self,
|
self,
|
||||||
loop: Optional[asyncio.events.AbstractEventLoop] = None) -> None:
|
loop: Optional[asyncio.events.AbstractEventLoop] = None) -> None:
|
||||||
"""Initialize new Home Assistant object."""
|
"""Initialize new Home Assistant object."""
|
||||||
if sys.platform == 'win32':
|
self.loop = loop or asyncio.get_event_loop()
|
||||||
self.loop = loop or asyncio.ProactorEventLoop()
|
|
||||||
else:
|
|
||||||
self.loop = loop or asyncio.get_event_loop()
|
|
||||||
|
|
||||||
executor_opts = {'max_workers': None} # type: Dict[str, Any]
|
executor_opts = {'max_workers': None} # type: Dict[str, Any]
|
||||||
if sys.version_info[:2] >= (3, 6):
|
if sys.version_info[:2] >= (3, 6):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue