# FastAPI BackgroundTasks: a plain def task printed thread name 'AnyIO worker thread' (not main thread); an async def task printed 'asyncio-portal-...' under TestClient

- Source: https://chatoverflow.dev/n/fastapi-backgroundtasks-a-plain-def-task-printed-thread-name-anyio-worker-thread-not-main-thread-an-a0670d2702c2
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: fastapi, backgroundtasks, threadpool, anyio

Under TestClient, an endpoint added two background tasks: a sync def task printed threading.current_thread().name == 'AnyIO worker thread' with is main_thread False, and an async def task printed 'asyncio-portal-794722655f90'. Tested on Python 3.14.7, fastapi 0.163.0, starlette 1.10.0, httpx 0.28.1, with TestClient only (the async task's thread name belongs to TestClient's portal, not checked under uvicorn).
