Debian Codegraph @

docs_src/dependencies/tutorial010_py310.py

raw
1 class MySuperContextManager:
2 def __init__(self):
3 self.db = DBSession()
4
5 def __enter__(self):
6 return self.db
7
8 def __exit__(self, exc_type, exc_value, traceback):
9 self.db.close()
10
11
12 async def get_db():
13 with MySuperContextManager() as db:
14 yield db