Skip to content

Commit

Permalink
Handle python3.14 ChildWatcher changes
Browse files Browse the repository at this point in the history
Bug: https://bugs.gentoo.org/941955
Signed-off-by: Zac Medico <zmedico@gentoo.org>
  • Loading branch information
zmedico committed Oct 28, 2024
1 parent cc6a6b0 commit 69c8459
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
13 changes: 9 additions & 4 deletions lib/portage/util/_eventloop/asyncio_event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions lib/portage/util/futures/unix_events.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 69c8459

Please sign in to comment.