Remove unnecessary asyncio EventLoopPolicy init_watcher backport (#129628)
This commit is contained in:
parent
ab5b9dbdc9
commit
5ed7d32749
1 changed files with 0 additions and 35 deletions
|
@ -3,10 +3,8 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from asyncio import events
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
|
@ -58,22 +56,6 @@ class RuntimeConfig:
|
||||||
safe_mode: bool = False
|
safe_mode: bool = False
|
||||||
|
|
||||||
|
|
||||||
def can_use_pidfd() -> bool:
|
|
||||||
"""Check if pidfd_open is available.
|
|
||||||
|
|
||||||
Back ported from cpython 3.12
|
|
||||||
"""
|
|
||||||
if not hasattr(os, "pidfd_open"):
|
|
||||||
return False
|
|
||||||
try:
|
|
||||||
pid = os.getpid()
|
|
||||||
os.close(os.pidfd_open(pid, 0))
|
|
||||||
except OSError:
|
|
||||||
# blocked by security policy like SECCOMP
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
|
class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
|
||||||
"""Event loop policy for Home Assistant."""
|
"""Event loop policy for Home Assistant."""
|
||||||
|
|
||||||
|
@ -81,23 +63,6 @@ class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
|
||||||
"""Init the event loop policy."""
|
"""Init the event loop policy."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self._watcher: asyncio.AbstractChildWatcher | None = None
|
|
||||||
|
|
||||||
def _init_watcher(self) -> None:
|
|
||||||
"""Initialize the watcher for child processes.
|
|
||||||
|
|
||||||
Back ported from cpython 3.12
|
|
||||||
"""
|
|
||||||
with events._lock: # type: ignore[attr-defined] # noqa: SLF001
|
|
||||||
if self._watcher is None: # pragma: no branch
|
|
||||||
if can_use_pidfd():
|
|
||||||
self._watcher = asyncio.PidfdChildWatcher()
|
|
||||||
else:
|
|
||||||
self._watcher = asyncio.ThreadedChildWatcher()
|
|
||||||
if threading.current_thread() is threading.main_thread():
|
|
||||||
self._watcher.attach_loop(
|
|
||||||
self._local._loop # type: ignore[attr-defined] # noqa: SLF001
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def loop_name(self) -> str:
|
def loop_name(self) -> str:
|
||||||
|
|
Loading…
Add table
Reference in a new issue