> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# stop

> Terminate a running task.

`Tasks.astop` cancels a running task. The platform marks it `Stopped`, signals the worker to abandon its current step, and returns the updated record.

```python theme={"dark"}
from xpander_sdk import Tasks

tasks = Tasks()
stopped = await tasks.astop(task_id="task_xyz")
print(stopped.status.value, stopped.is_manually_stopped)   # "stopped" True
```

### Parameters

| Parameter | Type  | Required | Description   |
| --------- | ----- | -------- | ------------- |
| `task_id` | `str` | Yes      | Task to stop. |

### Returns `Task`

The task record after the stop request was processed. `status` is `Stopped`, `is_manually_stopped` is `True`, and `finished_at` is set.

## Examples

### Stop from a running `Task` instance

If you already have the `Task` object, prefer the instance method:

```python theme={"dark"}
await task.astop()
print(task.status.value)   # "stopped"
```

`Task.astop()` and `Tasks().astop(task_id=task.id)` are equivalent: the instance method also updates the in-memory object.

### Idempotent stop

Calling `astop` on an already-terminal task is safe: the platform returns the existing record without changing state.

```python theme={"dark"}
# First call: stops it
await tasks.astop(task_id="task_xyz")

# Second call: no-op, returns the same record
await tasks.astop(task_id="task_xyz")
```

## Sync version

```python theme={"dark"}
tasks.stop(task_id="task_xyz")
```

## Errors

Raises [`ModuleException`](/developers/sdk-reference/error-handling). Common statuses:

| Status | Cause               |
| ------ | ------------------- |
| 404    | Task doesn't exist. |
| 500    | Server error.       |
