5ff8dfc5f9d5 draft — Alain Leufroy 7 months ago
wip
2 files changed, 24 insertions(+), 17 deletions(-)

M lairucrem/commands.py
M lairucrem/controler.py
M lairucrem/commands.py +4 -5
@@ 110,11 110,10 @@ class selection:
     async def fetch(self, node):
         for task in self._tasks.values():
             task.cancel()
-        self._tasks = {
-            name: asyncio.tasks.Task(coroutine(self, node))
-            for name, coroutine in self.selectors.items()
-        }
-        await asyncio.gather(*self._tasks.values())
+        self._tasks = {}
+        async with asyncio.TaskGroup() as task_group:
+            for name, coroutine in self.selectors.items():
+                self._tasks[name] = task_group.create_task(coroutine(self, node))
 
 
 @async_contextmanager

          
M lairucrem/controler.py +20 -12
@@ 42,11 42,15 @@ class _multiwalker(
 
     async def _wait(self):
         await super()._wait()
-        await asyncio.gather(*(walker.wait() for walker in self.__sequences__))
+        async with asyncio.TaskGroup() as task_group:
+            for walker in self.__sequences__:
+                task_group.create_task(walker.wait())
         urwid.emit_signal(self, 'completed')
 
     async def stop(self):
-        await asyncio.gather(*(walker.stop() for walker in self.__sequences__))
+        async with asyncio.TaskGroup() as task_group:
+            for walker in self.__sequences__:
+                task_group.create_task(walker.stop())
 
 
 class _hgwalker(ensurable, waitable, urwid.SimpleFocusListWalker):

          
@@ 74,6 78,10 @@ class _hgwalker(ensurable, waitable, urw
 
     async def __aiter__(self):
         async for line in self.aiterlines():
+            task = asyncio.tasks.current_task()
+            # config.logger.warning('%s %s' % (task._state, task, ))
+            if asyncio.tasks.current_task().cancelled():
+                break
             widget = self._get_widget(line)
             if widget:
                 yield widget

          
@@ 534,9 542,10 @@ class graphlistbox(
             # cwd was stripped. Doing more complicated stuff would be not useful.
             return await super()._wait()
         try:
-            await asyncio.gather(
-                super()._wait(),
-                dialog.popup_processing(
+            async with asyncio.TaskGroup() as task_group:
+                task_group.create_task(super()._wait())
+                task_group.create_task(
+                    dialog.popup_processing(
                     self._on_focus_rev(rev),
                     'Searching for the previous changeset... Close this popup to cancel.'
                 ))

          
@@ 639,13 648,12 @@ class patchlistwalker(_multiwalker):
         # Load task is specific order to ensure that prefered sections
         # appears quickly (PROCESSES_SEMAPHORE may delay a few of
         # them).
-        await asyncio.gather(
-            self._diff.wait(),
-            self._summary.wait(),
-            self._description.wait(),
-            self._diffstat.wait(),
-            self._summaryextra.wait(),
-        )
+        async with asyncio.TaskGroup() as task_group:
+            task_group.create_task(self._diff.wait())
+            task_group.create_task(self._summary.wait())
+            task_group.create_task(self._description.wait())
+            task_group.create_task(self._diffstat.wait())
+            task_group.create_task(self._summaryextra.wait())
         urwid.emit_signal(self, 'completed')