[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Start canceling pending tasks while closing a controller



commit 1072a8eef7b6d6327e0b329488d868439fc8d6df
Author: Illia Volochii <illia.volochii@xxxxxxxxx>
Date:   Tue Apr 14 23:59:32 2020 +0300

    Start canceling pending tasks while closing a controller
---
 stem/control.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 435fb741..b7ebe740 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -546,6 +546,7 @@ class BaseController(object):
     self._socket = control_socket
 
     self._asyncio_loop = asyncio.get_event_loop()
+    self._asyncio_loop_tasks = []
 
     self._msg_lock = threading.RLock()
 
@@ -724,6 +725,9 @@ class BaseController(object):
 
     await self._socket.close()
 
+    for task in self._asyncio_loop_tasks:
+      task.cancel()
+
     # Join on any outstanding state change listeners. Closing is a state change
     # of its own, so if we have any listeners it's quite likely there's some
     # work in progress.
@@ -898,8 +902,8 @@ class BaseController(object):
     them if we're restarted.
     """
 
-    self._asyncio_loop.create_task(self._reader_loop())
-    self._asyncio_loop.create_task(self._event_loop())
+    for coroutine in (self._reader_loop(), self._event_loop()):
+      self._asyncio_loop_tasks.append(self._asyncio_loop.create_task(coroutine))
 
 
   async def _reader_loop(self) -> None:



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits