mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Proactor policy fix (#17066)
* Proactor policy fix * Backport Proactor policy for <py37
This commit is contained in:
parent
1667481342
commit
1decba0052
@ -22,16 +22,30 @@ from homeassistant.const import (
|
|||||||
def set_loop() -> None:
|
def set_loop() -> None:
|
||||||
"""Attempt to use uvloop."""
|
"""Attempt to use uvloop."""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from asyncio.events import BaseDefaultEventLoopPolicy
|
||||||
|
|
||||||
|
policy = None
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
asyncio.set_event_loop(asyncio.ProactorEventLoop())
|
if hasattr(asyncio, 'WindowsProactorEventLoopPolicy'):
|
||||||
|
policy = asyncio.WindowsProactorEventLoopPolicy()
|
||||||
|
else:
|
||||||
|
class ProactorPolicy(BaseDefaultEventLoopPolicy):
|
||||||
|
"""Event loop policy to create proactor loops."""
|
||||||
|
|
||||||
|
_loop_factory = asyncio.ProactorEventLoop
|
||||||
|
|
||||||
|
policy = ProactorPolicy()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import uvloop
|
import uvloop
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
policy = uvloop.EventLoopPolicy()
|
||||||
|
|
||||||
|
if policy is not None:
|
||||||
|
asyncio.set_event_loop_policy(policy)
|
||||||
|
|
||||||
|
|
||||||
def validate_python() -> None:
|
def validate_python() -> None:
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import threading
|
import threading
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
from asyncio import coroutines
|
from asyncio import coroutines
|
||||||
from asyncio.events import AbstractEventLoop
|
from asyncio.events import AbstractEventLoop
|
||||||
from asyncio.futures import Future
|
from asyncio.futures import Future
|
||||||
@ -23,10 +22,7 @@ except AttributeError:
|
|||||||
|
|
||||||
def asyncio_run(main: Awaitable[_T], *, debug: bool = False) -> _T:
|
def asyncio_run(main: Awaitable[_T], *, debug: bool = False) -> _T:
|
||||||
"""Minimal re-implementation of asyncio.run (since 3.7)."""
|
"""Minimal re-implementation of asyncio.run (since 3.7)."""
|
||||||
if sys.platform == 'win32':
|
loop = asyncio.new_event_loop()
|
||||||
loop = asyncio.ProactorEventLoop()
|
|
||||||
else:
|
|
||||||
loop = asyncio.new_event_loop()
|
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
loop.set_debug(debug)
|
loop.set_debug(debug)
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user