Fire and forget (or never) with Python’s asyncio
TL;DR; Python’s asyncio.create_task() can silently garbage collect your fire-and-forget tasks starting in Python 3.12 - they may never run. The fix: store task references in a set and registe...

Source: Michael Kennedy's Thoughts on Technology
TL;DR; Python’s asyncio.create_task() can silently garbage collect your fire-and-forget tasks starting in Python 3.12 - they may never run. The fix: store task references in a set and register a done_callback to clean them up. Do you use Python’s async/await in programming? Often you have some async task that needs to run, but you don’t care to monitor it, know when it’s done, or even if it errors. Let’s imagine you have an async function that logs to a remote service. You want its execution out of the main-line execution. Maybe it looks like this: async def log_account_created(username: str): ... Someone new to Python’s odd version of async would think they could write code like this (hint, they cannot): async def register_user(): data = get_form_data() user = user_service.create_user(data) # Log in the background (actually no, but we try) log_account_created(user.name) # BUG! return redirect('/account/welcome') You cannot just run an async function