Closed WolfLink closed 4 weeks ago
So I found the issue. You are supposed to close()
coroutines if you aren't going to await
them. (It's also safe to close()
a coroutine after it has been await
ed). Neither happens when a task gets cancelled currently.
Relevant StackOverflow: https://stackoverflow.com/questions/62045387/how-to-suppress-coroutine-was-never-awaited-warning
I have two possible fixes to suggest:
__del__
for RuntimeTask
which will close its coroutine.close()
all relevant coroutines when cancel gets called.The 1st approach is a lot simpler. I'm pretty sure the warning happens when the unused coroutine gets garbage collected, so this approach is just letting python know it was ok for that coroutine to go unused.
The 2nd approach is a lot more work to implement, but it has a benfit in that if there is some future bug where a RuntimeTask
falls through the cracks when it wasn't supposed to be cancelled, the warning might pop up to let you know. The 1st approach will make it so any time a RuntimeTask
is never executed for any reason, the warning will not appear.
I have some code of the form:
I get warning messages of the form:
The line
hash_a = all(
is a seemingly random line of code each time. Note that the warnings don't show up every time; but they seem to show up more frequently when my CPU is under heavy load.It seems to be related to
get_runtime().cancel(my_future)
because if I replace that line withawait my_future
I no longer see the warnings (but the code takes undersireably longer obviously).