# Difference between Cancel and Terminate in Workflow

**URL:** <https://community.temporal.io/t/difference-between-cancel-and-terminate-in-workflow/13491>\
**Category:** Community Support\
**Tags:** python-sdk\
**Created:** [September 11, 2024, 12:28am UTC](https://community.temporal.io/t/difference-between-cancel-and-terminate-in-workflow/13491 "2024-09-11T00:28:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![psn999](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/psn999/32/4983_2.png) [@psn999](https://community.temporal.io/u/psn999)\
**Post date:** [September 11, 2024, 12:28am UTC](https://community.temporal.io/t/difference-between-cancel-and-terminate-in-workflow/13491/1 "2024-09-11T00:28:09Z")

</div>

When workflow is cancelled or terminated, in both the cases, `temporalio.exceptions.CancelledError` is raised.  
What’s the difference between cancel and terminate as in both the cases activity is able to perform a cleanup?

PS: Activity I have implemented are sync python activities, worker is instantiated with **activity\_executor** in order to run non-async activities, and worker graceful timeout is set to a very high duration…

PS: Other post mentions that termination is a hard stop of workflow, but that is not happening in this case  
References: [Difference between Cancel and Terminate - #2 by maxim](https://community.temporal.io/t/difference-between-cancel-and-terminate/759/2)

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [September 11, 2024, 3:20am UTC](https://community.temporal.io/t/difference-between-cancel-and-terminate-in-workflow/13491/2 "2024-09-11T03:20:53Z")

</div>

Termination is a hard stop of a workflow, not the worker. Please provide more information about what exactly is happening. Workflow history would help.

---

<div class="post-metadata">

**Author:** ![psn999](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/psn999/32/4983_2.png) [@psn999](https://community.temporal.io/u/psn999)\
**Post date:** [September 11, 2024, 6:09pm UTC](https://community.temporal.io/t/difference-between-cancel-and-terminate-in-workflow/13491/3 "2024-09-11T18:09:51Z")

</div>

I am sharing activity code

```auto
def run(self):
        try:
            for pct in range(0, 100, 1):
                activity.heartbeat(pct)
                # below sleep is similar to grpc/any client/database call
                # PS: time.sleep() is used just to emulate network/blocking calls, we should refrain from using sleep
                time.sleep(0.5)
        except CancelledError as ce:
            LOG.info(f'Received the error, {type(ce)}')
            # reraising the exception
            raise ce

```

This is how my worker params looks like

```auto
Worker(
   client,
   graceful_shutdown_timeout=timedelta(days=30),
   activity_executor=ThreadPoolExecutor(max_workers=10)
)

```

I did two experiments

1. Cancel the workflow running this activity.
2. Terminate the workflow running this activity.

I expected `Received the error...` log to be printed only in experiment 1.  
But even in experiment 2, activity is catching the CancelledError.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [September 11, 2024, 6:48pm UTC](https://community.temporal.io/t/difference-between-cancel-and-terminate-in-workflow/13491/4 "2024-09-11T18:48:15Z")

</div>

Terminating workflow (or completing it any other way) cancels all its activities. Cancellation gives the _workflow_ an ability to perform whatever business logic is needed for cleanup.
