Skip to content

Commit 81a7886

Browse files
authored
Move set_bind to before_serving hook and add close (#10)
Engine set_bind was in a before_first_request hook, and the engine was never closed. Moved the set_bind to a before_serving hook, and added a pop_bind/close to an after_serving hook. This also makes it easier to properly initialize engine in custom cli commands.
1 parent 3bef4cb commit 81a7886

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/gino_quart.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ async def after_response(response):
9797
del request.connection
9898
return response
9999

100-
@app.before_first_request
101-
async def before_first_request():
100+
@app.before_serving
101+
async def before_serving():
102102
dsn = app.config.get("DB_DSN")
103103
if not dsn:
104104
dsn = URL(
@@ -120,6 +120,10 @@ async def before_first_request():
120120
**app.config.setdefault("DB_KWARGS", dict()),
121121
)
122122

123+
@app.after_serving
124+
async def after_serving():
125+
await self.pop_bind().close()
126+
123127
async def first_or_404(self, *args, **kwargs):
124128
rv = await self.first(*args, **kwargs)
125129
if rv is None:

0 commit comments

Comments
 (0)