> For the complete documentation index, see [llms.txt](https://docs.hex-rays.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hex-rays.com/editions-and-licenses/license-types/ida-pro-headless/how-tos/wait-for-a-free-seat.md).

# Wait for a free seat

Each open database takes a seat, so a batch of scripts or agents can use all the seats of your pool. The next one then cannot open a database. This guide shows how to let it wait for a seat instead of failing.

## What happens when every seat is in use

When no seat is free, opening a database fails:

```
$ python examples/list_functions.py ~/sample
No seat from the license server: XX-XXXX-XXXX-XX: all license seats are in use
```

Your script can tell why IDA got no seat with `ida_license.get_license_error()`. `ida_license.get_license_error_message()` gives IDA's reason as text.

| `get_license_error()` | Meaning                                              | What to do                        |
| --------------------- | ---------------------------------------------------- | --------------------------------- |
| `LICENSE_ERR_RETRY`   | No free seat, or the license server can't be reached | Wait, then try again              |
| `LICENSE_ERR_FAILED`  | Anything else                                        | Fix the cause: waiting won't help |
| `LICENSE_ERR_NONE`    | Not a license problem                                | Check the file you opened         |

{% hint style="warning" %}
After a failed `open_database()`, call `close_database()` before you call `open_database()` again in the same process.
{% endhint %}

## Wait in your script

Set `IDA_LICENSE` to your license server, or to a borrow file on a machine that can't reach it:

```bash
export IDA_LICENSE=server:host=licsrv.example.com:port=65434   # your license server
export IDA_LICENSE=/path/to/<machine>.borrow                    # or, offline, a borrow file
```

Then open the database, and while it fails because no seat is free, close it, wait, and open it again:

```python
import idapro
import ida_license
import time

rc = idapro.open_database("sample.exe", run_auto_analysis=True)
while rc != 0:
    if ida_license.get_license_error() != ida_license.LICENSE_ERR_RETRY:
        raise SystemExit(ida_license.get_license_error_message())
    idapro.close_database()           # needed before opening again
    time.sleep(30)                    # no free seat yet: wait
    rc = idapro.open_database("sample.exe", run_auto_analysis=True)
...                                   # use the database
idapro.close_database()               # gives the seat back
```

## Or take the seat first

`examples/wait_for_seat.py` waits the other way: it takes a seat with `ida_license.set_license_server()` before it opens the database, and tries again while the license server says to retry. Once it has a seat, it opens the database with it:

```
$ python examples/wait_for_seat.py ~/sample --every 10
Try 1/20: No seat from the license server: XX-XXXX-XXXX-XX: all license seats are in use
Try 2/20: No seat from the license server: XX-XXXX-XXXX-XX: all license seats are in use
Try 3/20: No seat from the license server: XX-XXXX-XXXX-XX: all license seats are in use
Got a seat: triage-worker-1 from licsrv.example.com:65434
471 functions in ~/sample
```

`--every` sets the number of seconds between tries. The code that takes the seat, online or offline, is in `examples/licensing.py`.

For agents, the section **When no seat is free** of `AGENTS.md` gives both ways.

## If your scripts often wait

If your scripts often wait for seats, check the peak usage on the license server console. You may need more headless seats, or fewer scripts running at the same time. See [Headless seats](https://docs.hex-rays.com/editions-and-licenses/license-types/ida-pro-headless/concepts/headless-seats.md#how-many-seats-do-you-need).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hex-rays.com/editions-and-licenses/license-types/ida-pro-headless/how-tos/wait-for-a-free-seat.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
