Skip to content

Commit 76b5ead

Browse files
committed
cancel tasks
1 parent 6e67226 commit 76b5ead

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

buildingmotif/ingresses/bacnet.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def _run_async(self, coro):
6464
try:
6565
asyncio.set_event_loop(loop)
6666
loop.run_until_complete(coro)
67+
pending = [task for task in asyncio.all_tasks(loop) if not task.done()]
68+
if pending:
69+
for task in pending:
70+
task.cancel()
71+
loop.run_until_complete(
72+
asyncio.gather(*pending, return_exceptions=True)
73+
)
6774
loop.run_until_complete(loop.shutdown_asyncgens())
6875
finally:
6976
asyncio.set_event_loop(None)

0 commit comments

Comments
 (0)