From 6306c39f7aa560e7b84bf0e201d44c47e99b8247 Mon Sep 17 00:00:00 2001 From: Joongi Kim Date: Tue, 26 Apr 2022 09:41:41 +0000 Subject: [PATCH] fix: asyncio.PidfdChildWatcher may exist even in unsupported builds --- src/aiotools/server.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/aiotools/server.py b/src/aiotools/server.py index c45a0c8..57789fc 100644 --- a/src/aiotools/server.py +++ b/src/aiotools/server.py @@ -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 @@ -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