You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/manager/config.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,3 +88,23 @@ async with sa_manager.get_session() as session:
88
88
89
89
Note that async implementation has several differences from the sync one, make sure
90
90
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