-
-
Notifications
You must be signed in to change notification settings - Fork 482
Description
Summary
When creating tasks with create_task
, PyCord does not save a reference to a task.
Reproduction Steps
When creating tasks with create_task
, PyCord does not save a reference to a task, making it a target
for the garbage collector, if the task is doing long and complex work.
This is well documented by the asyncio.create_task
:
Save a reference to the result of this function, to avoid a task disappearing mid-execution. The event loop only keeps weak references to tasks. A task that isn’t referenced elsewhere may get garbage collected at any time, even before it’s done. For reliable “fire-and-forget” background tasks, gather them in a collection
This can eventually result in a "Task was destroyed but it is pending!" error being printed out on screen, because the task was garbage collected. It could also just go though without warning.
Minimal Reproducible Code
Hard to reproduce, it's a Heisenbug, but definitely possible.
Expected Results
The library should save references to task and only remove the reference after the task has been finished.
Actual Results
It doesn't, giving opportunity for the task to be destroyed during execution.
Intents
No intents were passed
System Information
- Python v3.11.1-final
- py-cord v2.4.1-final
- aiohttp v3.8.4
- system info: Windows 10 10.0.19045
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
No response