Skip to content

Commit ac7af04

Browse files
febus982claude
andcommitted
Document dispose_engines method and engine lifecycle
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4598799 commit ac7af04

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

docs/manager/config.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,23 @@ async with sa_manager.get_session() as session:
8888

8989
Note that async implementation has several differences from the sync one, make sure
9090
to check [SQLAlchemy asyncio documentation](https://docs.sqlalchemy.org/en/20/orm/extensions/asyncio.html)
91+
92+
## Bind engines lifecycle
93+
94+
Engine disposal is handled automatically by `SQLAlchemyBindManager`. Engines are disposed when:
95+
96+
* The manager instance is garbage collected
97+
* The Python interpreter shuts down (via an `atexit` handler)
98+
99+
In some scenarios, such as automated tests, you may need to manually dispose engines to release database connections between tests. The `dispose_engines()` method is available for this purpose:
100+
101+
```python
102+
sa_manager = SQLAlchemyBindManager(config)
103+
104+
# ... use the manager ...
105+
106+
# Manually dispose all engines
107+
sa_manager.dispose_engines()
108+
```
109+
110+
This method disposes all engines synchronously, including async engines (using their underlying sync engine).

0 commit comments

Comments
 (0)