# Celery

Integration with Celery.

## Setup

1. Set up Celery project.
2. Configure pyot models and pipelines.

```python
# Other imports ...
from pyot.conf.utils import import_confs

# Celery settings stuff ...

import_confs("<pyotconf_import_path>")
```

{% hint style="info" %}
Import path is the path used as if the file/module is being imported using python syntax via `import`, `__import__` or `importlib.import_module`
{% endhint %}

## Tasks

Celery does not support async functions, a util wrapper is provided `async_to_sync` in `pyot.utils.sync` to convert async functions into blocking functions.

{% hint style="danger" %}
Celery runs tasks in threads or processes, make sure to use resource managers for graceful handling of resources, refer to **Cores -> Resources**.
{% endhint %}

```python
from pyot.core.resources import resource_manager
from pyot.utils.sync import async_to_sync

# ...

@app.task
@async_to_sync
@resource_manager.as_decorator
async def task_using_decorator():
    ...

# OR

@app.task
@async_to_sync
async def task_using_context_manager():
    async with resource_manager():
        ...
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pyot.iann838.com/integrations/celery.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
