From 30ac3926f709e3263211009f9707b0ad187a956f Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Mon, 12 Dec 2022 21:21:38 +0100 Subject: save strong references of newly created tasks in the `TASKS` set --- pydis_core/utils/scheduling.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pydis_core/utils/scheduling.py') diff --git a/pydis_core/utils/scheduling.py b/pydis_core/utils/scheduling.py index eced4a3d..8f9d711c 100644 --- a/pydis_core/utils/scheduling.py +++ b/pydis_core/utils/scheduling.py @@ -10,6 +10,8 @@ from functools import partial from pydis_core.utils import logging +TASKS = set[asyncio.Task] + class Scheduler: """ @@ -238,6 +240,9 @@ def create_task( task = event_loop.create_task(coro, **kwargs) else: task = asyncio.create_task(coro, **kwargs) + + TASKS.add(task) + task.add_done_callback(TASKS.discard) task.add_done_callback(partial(_log_task_exception, suppressed_exceptions=suppressed_exceptions)) return task -- cgit v1.2.3