aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2020-03-07 12:25:40 -0800
committerZac Medico <zmedico@gentoo.org>2020-03-07 12:28:50 -0800
commitc1b19c2415c2f85074634da0c29350d905188c6f (patch)
tree8033929ea15054adbbba1b866949f5c091b1cfff /lib
parentAsynchronousTask: simplify isAlive (bug 711688) (diff)
downloadportage-c1b19c2415c2f85074634da0c29350d905188c6f.tar.gz
portage-c1b19c2415c2f85074634da0c29350d905188c6f.tar.bz2
portage-c1b19c2415c2f85074634da0c29350d905188c6f.zip
AsynchronousTask: handle addStartListener after exit (bug 711322)
When addStartListener is called after the task has already exited with a returncode, immediately schedule the listener to be invoked via call_soon. This behavior is similar to the Future add_done_callback method (and addExitListener since commit 5d476c4e5002). Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/_emerge/AsynchronousTask.py8
-rw-r--r--lib/portage/tests/util/futures/test_done_callback_after_exit.py4
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/_emerge/AsynchronousTask.py b/lib/_emerge/AsynchronousTask.py
index 97db02587..ec5497b69 100644
--- a/lib/_emerge/AsynchronousTask.py
+++ b/lib/_emerge/AsynchronousTask.py
@@ -156,6 +156,10 @@ class AsynchronousTask(SlotObject):
self._start_listeners = []
self._start_listeners.append(f)
+ # Ensure that start listeners are always called.
+ if self.returncode is not None:
+ self._start_hook()
+
def removeStartListener(self, f):
if self._start_listeners is None:
return
@@ -198,6 +202,10 @@ class AsynchronousTask(SlotObject):
used to trigger exit listeners when the returncode first
becomes available.
"""
+ # Ensure that start listeners are always called.
+ if self.returncode is not None:
+ self._start_hook()
+
if self.returncode is not None and \
self._exit_listeners is not None:
diff --git a/lib/portage/tests/util/futures/test_done_callback_after_exit.py b/lib/portage/tests/util/futures/test_done_callback_after_exit.py
index 46a51c271..8913d70e5 100644
--- a/lib/portage/tests/util/futures/test_done_callback_after_exit.py
+++ b/lib/portage/tests/util/futures/test_done_callback_after_exit.py
@@ -36,5 +36,9 @@ class DoneCallbackAfterExitTestCase(TestCase):
for i in range(3):
event = loop.create_future()
+ task.addStartListener(lambda task: event.set_result(None))
+ loop.run_until_complete(event)
+
+ event = loop.create_future()
task.addExitListener(lambda task: event.set_result(None))
loop.run_until_complete(event)