add balance

This commit is contained in:
Yuriy Yuriev
2026-05-14 21:04:28 +07:00
parent bdf3fef7ec
commit fe9ada0558
7 changed files with 734 additions and 170 deletions
+7 -12
View File
@@ -116,21 +116,16 @@ class BackgroundTaskManager:
Returns:
Number of tasks cancelled
"""
cancelled = 0
async with self._lock:
for task in list(self._tasks.values()):
if not task.done():
task.cancel()
try:
await task
except asyncio.CancelledError:
pass
cancelled += 1
running = [t for t in self._tasks.values() if not t.done()]
for task in running:
task.cancel()
if running:
await asyncio.gather(*running, return_exceptions=True)
self._tasks.clear()
self._task_info.clear()
cancelled = len(running)
logger.info(f"All tasks cancelled: {cancelled}")
return cancelled