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') 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 From 4dc7593d92b1572d43947df0cba21cf4e1feb342 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 19:23:40 +0100 Subject: save newly created tasks in a set --- pydis_core/utils/scheduling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pydis_core/utils') diff --git a/pydis_core/utils/scheduling.py b/pydis_core/utils/scheduling.py index 8f9d711c..7987024c 100644 --- a/pydis_core/utils/scheduling.py +++ b/pydis_core/utils/scheduling.py @@ -10,7 +10,7 @@ from functools import partial from pydis_core.utils import logging -TASKS = set[asyncio.Task] +_background_tasks = set[asyncio.Task] class Scheduler: @@ -241,8 +241,8 @@ def create_task( else: task = asyncio.create_task(coro, **kwargs) - TASKS.add(task) - task.add_done_callback(TASKS.discard) + _background_tasks.add(task) + task.add_done_callback(_background_tasks.discard) task.add_done_callback(partial(_log_task_exception, suppressed_exceptions=suppressed_exceptions)) return task -- cgit v1.2.3 From 31265fddebf0179c914139eef0d8f5d279aa3932 Mon Sep 17 00:00:00 2001 From: Amrou Bellalouna Date: Fri, 23 Dec 2022 19:35:54 +0100 Subject: fix instantiation of bg tasks set --- pydis_core/utils/scheduling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_core/utils') diff --git a/pydis_core/utils/scheduling.py b/pydis_core/utils/scheduling.py index 7987024c..d4458bc1 100644 --- a/pydis_core/utils/scheduling.py +++ b/pydis_core/utils/scheduling.py @@ -10,7 +10,7 @@ from functools import partial from pydis_core.utils import logging -_background_tasks = set[asyncio.Task] +_background_tasks: set[asyncio.Task] = set() class Scheduler: -- cgit v1.2.3