Groo12 commited on
Commit
09effdc
·
1 Parent(s): af4689d

Add application file

Browse files
Files changed (1) hide show
  1. main.py +7 -3
main.py CHANGED
@@ -20,9 +20,13 @@ db = None
20
  @asynccontextmanager
21
  async def lifespan(app):
22
  global db
23
- db = Database() # Initialize database connection
24
- yield
25
- db.conn.close() # Close connection on shutdown
 
 
 
 
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