go → spawn registry
go f(x) spawns a task in the background. Lowers through typhon_runtime.tasks.spawn, never a bare asyncio.create_task.
Async context
async def signup(email: str) -> User: let user: User = await create_user(email) go send_welcome(user) return userfrom typhon_runtime import tasks
async def signup(email: str) -> User: user: User = await create_user(email) tasks.spawn(send_welcome(user)) return userWith handle
async def signup(email: str) -> User: let user: User = await create_user(email) go send_welcome(user) -> email_task await email_task return userfrom typhon_runtime import tasks
async def signup(email: str) -> User: user: User = await create_user(email) email_task = tasks.spawn(send_welcome(user)) await email_task return userThe runtime helper
import asyncio
_BACKGROUND: set[asyncio.Task] = set()
def spawn(coro): task = asyncio.create_task(coro) _BACKGROUND.add(task) task.add_done_callback(_BACKGROUND.discard) return taskfrom typhon_runtime import tasks_threaded as tasks
def heavy_work(): ...
def run() -> None: fut = tasks.spawn(heavy_work) # ...10 lines, generated into your build/ tree. Solves the well-known footgun: Python’s event loop holds only weak references to tasks. A fire-and-forget asyncio.create_task(...) whose handle is dropped can be garbage-collected mid-flight. The _BACKGROUND set holds strong references; the done-callback clears entries on completion.
Free-threaded variant
go always lowers through typhon_runtime.tasks.spawn (an asyncio task held in a strong-ref registry) — there is no ThreadPoolExecutor lowering for go, including when [python] free-threaded = true.
Why never asyncio.create_task directly?
This is a well-known CPython gotcha — see the asyncio docs for the warning. Tasks are weakly referenced by the loop. Without an external strong reference, the GC may collect the task and silently cancel the coroutine.
The runtime helper takes one line of overhead and prevents the entire bug class.
Where next
async,await,gather,goreference — full surface.- Async and Concurrency (tour) — teaching page.
- The typhon_runtime module — every helper.