ambitious-nightfall-95292
02/18/2026, 4:07 AMancient-wolf-19325
02/18/2026, 4:07 AMasyncio.CancelledError (for programmatic cancellation) or a flyte.errors.ActionAbortedError (for external aborts), and you can place cleanup code in the corresponding exception handler. There is no explicit support for registering a separate cleanup task to be triggered on abort outside of this pattern, according to the documentation and examples provided in the data sources.
Here is a pattern for handling cleanup on abort within a task:
import asyncio
import flyte
import flyte.errors
@flyte.task
async def my_task():
try:
# main logic here
await asyncio.sleep(100)
except (asyncio.CancelledError, flyte.errors.ActionAbortedError):
# cleanup logic here
print("Cleanup on abort")
return
As per the documentation, this is the recommended approach for cleanup on aborts in Flyte tasks. Would you like more detail or a more advanced example?
Sources:
- Abort and cancel actions
- Abort and cancel actions (BYOC)
- llms-full.txt
- Code example: abort-tasks
- Code example: external abort 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.ambitious-nightfall-95292
02/18/2026, 4:14 AMambitious-nightfall-95292
02/18/2026, 4:17 AMancient-wolf-19325
02/18/2026, 4:17 AMasyncio.CancelledError or ActionAbortedError within task code) are documented for Flyte V2 only. There is no mention of a built-in or recommended cleanup-on-abort pattern for Flyte V1 in the available sources.
Would you like more detail or guidance on possible workarounds based on general Python or Kubernetes patterns?
Sources:
- Abort and cancel actions
- Abort and cancel actions (BYOC) 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.