diff --git a/lib/portage/tests/util/futures/asyncio/test_policy_wrapper_recursion.py b/lib/portage/tests/util/futures/asyncio/test_policy_wrapper_recursion.py index 3896f91acb..d22d0241ee 100644 --- a/lib/portage/tests/util/futures/asyncio/test_policy_wrapper_recursion.py +++ b/lib/portage/tests/util/futures/asyncio/test_policy_wrapper_recursion.py @@ -1,4 +1,4 @@ -# Copyright 2018 Gentoo Foundation +# Copyright 2018-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import asyncio @@ -17,7 +17,8 @@ def testPolicyWrapperRecursion(self): with self.assertRaises(NotImplementedError): asyncio.get_event_loop() - with self.assertRaises(NotImplementedError): - asyncio.get_child_watcher() + if hasattr(asyncio, "get_child_watcher"): + with self.assertRaises(NotImplementedError): + asyncio.get_child_watcher() finally: asyncio.set_event_loop_policy(initial_policy) diff --git a/lib/portage/util/_eventloop/asyncio_event_loop.py b/lib/portage/util/_eventloop/asyncio_event_loop.py index c69e5c2f01..ad1dd387bf 100644 --- a/lib/portage/util/_eventloop/asyncio_event_loop.py +++ b/lib/portage/util/_eventloop/asyncio_event_loop.py @@ -6,12 +6,16 @@ import asyncio as _real_asyncio from asyncio.events import AbstractEventLoop as _AbstractEventLoop -from asyncio.unix_events import ThreadedChildWatcher try: - from asyncio.unix_events import PidfdChildWatcher + from asyncio.unix_events import _ThreadedChildWatcher as ThreadedChildWatcher except ImportError: - PidfdChildWatcher = None + from asyncio.unix_events import ThreadedChildWatcher + +try: + from asyncio.unix_events import _PidfdChildWatcher as PidfdChildWatcher +except ImportError: + from asyncio.unix_events import PidfdChildWatcher import portage @@ -123,7 +127,8 @@ def _asyncio_child_watcher(self): else: watcher = ThreadedChildWatcher() - watcher.attach_loop(self._loop) + if hasattr(watcher, "attach_loop"): + watcher.attach_loop(self._loop) self._child_watcher = _ChildWatcherThreadSafetyWrapper(self, watcher) return self._child_watcher diff --git a/lib/portage/util/futures/unix_events.py b/lib/portage/util/futures/unix_events.py index 374497010c..370cafb001 100644 --- a/lib/portage/util/futures/unix_events.py +++ b/lib/portage/util/futures/unix_events.py @@ -1,14 +1,10 @@ -# Copyright 2018-2021 Gentoo Authors +# Copyright 2018-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -__all__ = ( - "AbstractChildWatcher", - "DefaultEventLoopPolicy", -) +__all__ = ("DefaultEventLoopPolicy",) import asyncio as _real_asyncio from asyncio import events -from asyncio.unix_events import AbstractChildWatcher import fcntl import os