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

# Closing event loops (tai42_kit.loop_closing)

> The mark a loop's end sets before it releases the loop's resources, and the refusal every loop-bound owner raises on a new lease against a closing loop.

The event loops that are closing, and the refusal every owner of a loop-bound resource raises on one.

A loop is closing once the code that ends it has marked it so, at the start of its end, before it
awaits the release of the loop's resources (`close` does;
`release_loop_bound_resources` itself marks nothing, since a loop that
lives on leases anew after a release). From then on every owner the kit keeps per loop (the pooled
clients, the resource registries) refuses a new lease on that loop with `RuntimeError`, as a closed
connection pool refuses a new connection: a resource the release has already passed would otherwise
be opened anew and stay open past the loop's close. A lease held before the mark keeps working until it is released.

A loop stays closing for the rest of its life; the mark drops with the loop. The set is reached
from every thread that runs a loop, so it is read and written under a lock.

## mark\_loop\_closing

`tai42_kit.loop_closing.mark_loop_closing`

```python theme={null}
mark_loop_closing(loop: AbstractEventLoop) -> None
```

Mark `loop` as closing: every owner of a loop-bound resource refuses a new lease on it from now on.

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `loop` | `AbstractEventLoop` | — | — |

## loop\_is\_closing

`tai42_kit.loop_closing.loop_is_closing`

```python theme={null}
loop_is_closing(loop: AbstractEventLoop) -> bool
```

Whether `loop` has been marked closing.

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `loop` | `AbstractEventLoop` | — | — |

## refuse\_lease\_on\_closing\_loop

`tai42_kit.loop_closing.refuse_lease_on_closing_loop`

```python theme={null}
refuse_lease_on_closing_loop(loop: AbstractEventLoop, owner: str, lease: str) -> None
```

Raise `RuntimeError` when `loop` is closing, naming `owner` and the `lease` it refuses.

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `loop` | `AbstractEventLoop` | — | — |
| `owner` | `str` | — | — |
| `lease` | `str` | — | — |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.