Skip to content

Commit

Permalink
SchedulerInterface/PollScheduler: Add _loop property
Browse files Browse the repository at this point in the history
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: 389bb30 ("async_aux_get: Use EbuildMetadataPhase deallocate_config future")
Bug: https://bugs.gentoo.org/925333
Signed-off-by: Zac Medico <zmedico@gentoo.org>
  • Loading branch information
zmedico committed Feb 24, 2024
1 parent 01d06eb commit acb69a6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/_emerge/PollScheduler.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -39,6 +39,13 @@ def __init__(self, main=False, event_loop=None):
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

Expand Down
2 changes: 1 addition & 1 deletion lib/portage/dbapi/porttree.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ async def async_aux_get(self, mycpv, mylist, mytree=None, myrepo=None, loop=None
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()
Expand Down
3 changes: 2 additions & 1 deletion lib/portage/tests/ebuild/test_doebuild_spawn.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -86,6 +86,7 @@ def testDoebuildSpawn(self):
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
Expand Down
3 changes: 2 additions & 1 deletion lib/portage/tests/ebuild/test_ipc_daemon.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -77,6 +77,7 @@ def testIpcDaemon(self):
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

Expand Down
9 changes: 8 additions & 1 deletion lib/portage/util/_async/SchedulerInterface.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,6 +49,13 @@ def __init__(self, event_loop, is_background=None, **kwargs):
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
Expand Down

0 comments on commit acb69a6

Please sign in to comment.