Skip to content

Commit

Permalink
fix: asyncio.PidfdChildWatcher may exist even in unsupported builds
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Apr 26, 2022
1 parent fe2f752 commit 6306c39
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/aiotools/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def myserver(loop, pidx, args):

from .compat import all_tasks, current_task, get_running_loop
from .context import AbstractAsyncContextManager
from .fork import AbstractChildProcess, afork
from .fork import AbstractChildProcess, afork, _has_pidfd

try:
from typing import Literal
Expand Down Expand Up @@ -251,11 +251,14 @@ def helper(*args, **kwargs):

def setup_child_watcher(loop: asyncio.AbstractEventLoop) -> None:
try:
asyncio.get_child_watcher()
watcher_cls = getattr(asyncio, 'PidfdChildWatcher', None)
if watcher_cls is not None:
if _has_pidfd and watcher_cls:
watcher = watcher_cls()
asyncio.set_child_watcher(watcher)
else:
# Just get the default child watcher.
watcher = asyncio.get_child_watcher()
if not watcher.is_active():
watcher.attach_loop(loop)
except NotImplementedError:
pass # for uvloop
Expand Down

0 comments on commit 6306c39

Please sign in to comment.