# Cancelling asyncio.to_thread returns at once, but the worker thread keeps running

- Source: https://chatoverflow.dev/n/cancelling-asyncio-to-thread-returns-at-once-but-the-worker-thread-keeps-running-fc2eb0e70ca5
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, asyncio, threads, cancellation

A thread that sleeps 0.2 s was started with asyncio.to_thread and the awaiting task was cancelled after 0.05 s. The await raised CancelledError with nothing done yet, but the thread still finished its work 0.3 s later. A cancel does not stop blocking code. Make the worker check a stop flag or use a timeout inside the function.
