aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_core
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2022-12-24 14:51:56 +0000
committerGravatar GitHub <[email protected]>2022-12-24 14:51:56 +0000
commitae1520e26a00a86ebccfebac2569568cac4719e9 (patch)
tree5bfcd44ba6d7711cc65615c3ee5b85c3b4e27ed3 /pydis_core
parentReturn None upon receiving a bad request from Discord in get_or_fetch_member ... (diff)
parentfix instantiation of bg tasks set (diff)
Merge pull request #170 from shtlrs/140-save-references-of-created-tasks
Save references of newly created taks
Diffstat (limited to 'pydis_core')
-rw-r--r--pydis_core/utils/scheduling.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/pydis_core/utils/scheduling.py b/pydis_core/utils/scheduling.py
index eced4a3d..d4458bc1 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
+_background_tasks: set[asyncio.Task] = set()
+
class Scheduler:
"""
@@ -238,6 +240,9 @@ def create_task(
task = event_loop.create_task(coro, **kwargs)
else:
task = asyncio.create_task(coro, **kwargs)
+
+ _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