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 with engines 
or connections, then db.close() won't block.

If you aren't doing anything with the database then I can't imagine why you'd 
want to use a Session inside of an async though. 

On Sun, Jun 2, 2019, at 4:05 AM, Chris Withers wrote:
> 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 Session, which is a sessionmaker, or 
> db.close(), be expected to block?
> I can't remember whether instantiating a session will open a network 
> connection, or whether close will similarly do network io, so thought 
> I'd ask...
> 
> Chris
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/67f180de-a6c1-a28b-8c6f-b850b3775519%40withers.org.
> For more options, visit https://groups.google.com/d/optout.
> 

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/3c403634-8e31-4709-bc74-2155236c5d47%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to