Skip to content

Commit 1410af5

Browse files
committed
fix SAWarning: The garbage collector is trying to clean up non-checked-in connection
1 parent f8d4bf4 commit 1410af5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66

77
@asynccontextmanager
88
async def lifespan(app: FastAPI):
9-
await engine.connect()
10-
yield
11-
# You can also close DB connections here if needed
12-
print("App shutdown complete.")
9+
print("🚀 App starting...")
10+
11+
# ✅ Properly open a connection context
12+
async with engine.begin() as conn:
13+
# optional: run startup scripts (like create_all)
14+
pass
15+
16+
yield # App is running
17+
18+
print("🧹 App shutting down...")
1319
await engine.dispose()
20+
print("✅ App shutdown complete.")
1421

1522

1623
app = FastAPI(lifespan=lifespan, description="Template for building FastAPI applications with PostgreSQL", contact={"email": "samanidarix@gmail.com"})

0 commit comments

Comments
 (0)