commit:     acb69a6f234bd412e95e76f5c1db1b1f5b8e1dc5
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 24 03:52:47 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Feb 24 04:23:27 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=acb69a6f

SchedulerInterface/PollScheduler: Add _loop property

This allows async_aux_get to easily verify the identity of
the underlying loop so that this assertion will not fail:

_start_with_metadata
    (settings.configdict["pkg"]["SRC_URI"],) = aux_get_task.future.result()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/portage/dbapi/porttree.py", line 786, 
in async_aux_get
    raise AssertionError(
AssertionError: async_aux_get called from thread <_MainThread(MainThread, 
started 281473559502880)> with loop <_emerge.Scheduler.Scheduler._iface_class 
object at 0xffff8e3a8840>
Terminated

Fixes: 389bb304abf5 ("async_aux_get: Use EbuildMetadataPhase deallocate_config 
future")
Bug: https://bugs.gentoo.org/925333
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/_emerge/PollScheduler.py                    | 9 ++++++++-
 lib/portage/dbapi/porttree.py                   | 2 +-
 lib/portage/tests/ebuild/test_doebuild_spawn.py | 3 ++-
 lib/portage/tests/ebuild/test_ipc_daemon.py     | 3 ++-
 lib/portage/util/_async/SchedulerInterface.py   | 9 ++++++++-
 5 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/lib/_emerge/PollScheduler.py b/lib/_emerge/PollScheduler.py
index e5dffd8afa..b5bfd20b76 100644
--- a/lib/_emerge/PollScheduler.py
+++ b/lib/_emerge/PollScheduler.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import threading
@@ -39,6 +39,13 @@ class PollScheduler:
             self._event_loop, is_background=self._is_background
         )
 
+    @property
+    def _loop(self):
+        """
+        Returns the real underlying asyncio loop.
+        """
+        return self._event_loop._loop
+
     def _is_background(self):
         return self._background
 

diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py
index 4eebe1183f..de6aa5c82b 100644
--- a/lib/portage/dbapi/porttree.py
+++ b/lib/portage/dbapi/porttree.py
@@ -775,7 +775,7 @@ class portdbapi(dbapi):
             try:
                 if (
                     threading.current_thread() is threading.main_thread()
-                    and loop is asyncio._safe_loop()
+                    and loop._loop is asyncio._safe_loop()._loop
                 ):
                     # In this case use self._doebuild_settings_lock to manage 
concurrency.
                     deallocate_config = loop.create_future()

diff --git a/lib/portage/tests/ebuild/test_doebuild_spawn.py 
b/lib/portage/tests/ebuild/test_doebuild_spawn.py
index 9fb2c7fdd4..cac844f8fb 100644
--- a/lib/portage/tests/ebuild/test_doebuild_spawn.py
+++ b/lib/portage/tests/ebuild/test_doebuild_spawn.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2015 Gentoo Foundation
+# Copyright 2010-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import textwrap
@@ -86,6 +86,7 @@ class DoebuildSpawnTestCase(TestCase):
             open(os.path.join(settings["T"], "environment"), "wb").close()
 
             scheduler = SchedulerInterface(global_event_loop())
+            self.assertTrue(scheduler._loop is global_event_loop()._loop)
             for phase in ("_internal_test",):
                 # Test EbuildSpawnProcess by calling doebuild.spawn() with
                 # returnpid=False. This case is no longer used by portage

diff --git a/lib/portage/tests/ebuild/test_ipc_daemon.py 
b/lib/portage/tests/ebuild/test_ipc_daemon.py
index 0beb69ddfc..b8777fe94b 100644
--- a/lib/portage/tests/ebuild/test_ipc_daemon.py
+++ b/lib/portage/tests/ebuild/test_ipc_daemon.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2023 Gentoo Authors
+# Copyright 2010-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import tempfile
@@ -77,6 +77,7 @@ class IpcDaemonTestCase(TestCase):
                 task_scheduler = TaskScheduler(
                     iter([daemon, proc]), max_jobs=2, event_loop=event_loop
                 )
+                self.assertTrue(task_scheduler._loop is event_loop._loop)
 
                 self.received_command = False
 

diff --git a/lib/portage/util/_async/SchedulerInterface.py 
b/lib/portage/util/_async/SchedulerInterface.py
index 43a42adff2..485958491a 100644
--- a/lib/portage/util/_async/SchedulerInterface.py
+++ b/lib/portage/util/_async/SchedulerInterface.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2021 Gentoo Authors
+# Copyright 2012-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import gzip
@@ -49,6 +49,13 @@ class SchedulerInterface(SlotObject):
         for k in self._event_loop_attrs:
             setattr(self, k, getattr(event_loop, k))
 
+    @property
+    def _loop(self):
+        """
+        Returns the real underlying asyncio loop.
+        """
+        return self._event_loop._loop
+
     @staticmethod
     def _return_false():
         return False

Reply via email to