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

# Ensure Run Lock • AI Agent SDK

> ensure_run_lock: Lazily mint obj._run_lock under a shared module guard.

# ensure\_run\_lock

Function

> This function is defined in the [**\_run\_lock**](https://praison.ai/docs/sdk/reference/praisonaiagents/modules/_run_lock.md) module.

Lazily mint `obj._run_lock` under a shared module guard.

`getattr(obj, "_run_lock", None)` works for both the dataclass-field case
(Workflow) and the plain-attribute case (AgentTeam), so the behaviour is
identical to the per-module implementations it replaces.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def ensure_run_lock(obj) -> Any
```

## Parameters

**obj** `Any` *required*

The orchestration instance (AgentTeam or Workflow) whose per-instance `_run_lock` should be returned, creating it on first access.

### Returns

**Returns** `Any`

The instance's `_run_lock` — the same object for every caller under a concurrent first-access race.

## Uses

* `getattr`
* `threading.Lock`

## Source

> **[View on GitHub](https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/_run_lock.py#L18)**
>
> `praisonaiagents/_run_lock.py` at line 18

***

## Related Documentation

> **[Concurrency](https://praison.ai/docs/docs/features/concurrency)**

> **[Thread Safety](https://praison.ai/docs/docs/features/thread-safety)**

> **[AgentTeam Batch](https://praison.ai/docs/docs/features/agentteam-batch)**

> **[Workflows Feature](https://praison.ai/docs/docs/features/workflows)**


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