[sqlalchemy] Will calling a sessionmaker or closing a session block?

2019-06-02 Thread Chris Withers
Hi All, Given this async function (asgi middleware, as it happens): @app.middleware('http') async def make_db_session(request: Request, call_next):     request.state.db = Session()     response = await call_next(request)     request.state.db.close()     return response Would either the call to

Re: [sqlalchemy] Will calling a sessionmaker or closing a session block?

2019-06-02 Thread Mike Bayer
So that's an empty Session, which won't do anything immediately, however if anything is done on it that uses a database, then that all blocks, and if so, db.close() can also block because it has to cleanup the database connection which is definitely blocking IO stuff. If you didn't do anything