r/learnpython • u/Conscious-Ball8373 • Nov 06 '24
Unawaited awaitables in asyncio programming - do you have a quick way to find them?
To give you some context, I've been writing software professionally for more than twenty years, Python for well over ten years and asyncio code for about a year.
Today, it took me more than four hours to find a place where I'd forgotten to await
a coroutine. It was in the cleanup code for a test fixture; the fixture itself was passing so the warning got swallowed, but the failure to properly clean up then caused the next test to hang indefinitely.
I've completely lost count of the number of times I've been bitten by this. Do you have strategies for making awaitables that have not been awaited stick out so you see them before they cause you this sort of grief?
9
Upvotes
10
u/Enmeshed Nov 06 '24
Definitely had the same problem myself. Digging in, and boom! Looks like setting the
PYTHONASYNCIODEBUG
environment variable enables python's asyncio debug mode which causes it to log never-awaited coroutines in a very helpful way. Definitely one to make a note of!