|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import asyncio |
6 | | -from asyncio import events |
7 | 6 | import dataclasses |
8 | 7 | import logging |
9 | | -import os |
10 | 8 | import subprocess |
11 | 9 | import threading |
12 | 10 | from time import monotonic |
@@ -58,46 +56,13 @@ class RuntimeConfig: |
58 | 56 | safe_mode: bool = False |
59 | 57 |
|
60 | 58 |
|
61 | | -def can_use_pidfd() -> bool: |
62 | | - """Check if pidfd_open is available. |
63 | | -
|
64 | | - Back ported from cpython 3.12 |
65 | | - """ |
66 | | - if not hasattr(os, "pidfd_open"): |
67 | | - return False |
68 | | - try: |
69 | | - pid = os.getpid() |
70 | | - os.close(os.pidfd_open(pid, 0)) |
71 | | - except OSError: |
72 | | - # blocked by security policy like SECCOMP |
73 | | - return False |
74 | | - return True |
75 | | - |
76 | | - |
77 | 59 | class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy): |
78 | 60 | """Event loop policy for Home Assistant.""" |
79 | 61 |
|
80 | 62 | def __init__(self, debug: bool) -> None: |
81 | 63 | """Init the event loop policy.""" |
82 | 64 | super().__init__() |
83 | 65 | self.debug = debug |
84 | | - self._watcher: asyncio.AbstractChildWatcher | None = None |
85 | | - |
86 | | - def _init_watcher(self) -> None: |
87 | | - """Initialize the watcher for child processes. |
88 | | -
|
89 | | - Back ported from cpython 3.12 |
90 | | - """ |
91 | | - with events._lock: # type: ignore[attr-defined] # noqa: SLF001 |
92 | | - if self._watcher is None: # pragma: no branch |
93 | | - if can_use_pidfd(): |
94 | | - self._watcher = asyncio.PidfdChildWatcher() |
95 | | - else: |
96 | | - self._watcher = asyncio.ThreadedChildWatcher() |
97 | | - if threading.current_thread() is threading.main_thread(): |
98 | | - self._watcher.attach_loop( |
99 | | - self._local._loop # type: ignore[attr-defined] # noqa: SLF001 |
100 | | - ) |
101 | 66 |
|
102 | 67 | @property |
103 | 68 | def loop_name(self) -> str: |
|
0 commit comments