Spaces:
Runtime error
Runtime error
Add application file
Browse files
main.py
CHANGED
|
@@ -20,9 +20,13 @@ db = None
|
|
| 20 |
@asynccontextmanager
|
| 21 |
async def lifespan(app):
|
| 22 |
global db
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
app.router.lifespan_context = lifespan
|
| 28 |
|
|
|
|
| 20 |
@asynccontextmanager
|
| 21 |
async def lifespan(app):
|
| 22 |
global db
|
| 23 |
+
try:
|
| 24 |
+
db = Database()
|
| 25 |
+
yield
|
| 26 |
+
finally:
|
| 27 |
+
if db:
|
| 28 |
+
db.conn.close()
|
| 29 |
+
|
| 30 |
|
| 31 |
app.router.lifespan_context = lifespan
|
| 32 |
|