# Moose / Workflows / Cancel Workflow Documentation – Python ## Included Files 1. moose/workflows/cancel-workflow/cancel-workflow.mdx ## cancel-workflow Source: moose/workflows/cancel-workflow/cancel-workflow.mdx # Cancel a Running Workflow To stop a workflow before it has finished running, use the `workflow cancel` command. ```bash filename="Terminal" copy moose workflow cancel ``` ### Implementing Cancelation Callbacks For workflows that are running and have clean up operations to perform, you can implement a termination callback. This is especially useful for any long running tasks that have open connections or subscriptions to other services that need to be closed. You may also use the `state` within the run/cancel context to supplement your business logic. ```python filename="workflows/workflows.py" copy def run_task1(ctx: TaskContext[Foo]) -> None: connection.open() def on_cancel(ctx: TaskContext[Foo]) -> None: # Clean up any resources connection.close() task1 = Task[Foo, None]( name="task1", config=TaskConfig(run=run_task1, on_cancel=on_cancel) ) myworkflow = Workflow( name="myworkflow", config=WorkflowConfig(starting_task=task1, retries=3) ) ```