I'm wondering where the best place would be to create a scoped session for use in falcon.
From reading the flask-sqlalchemy code, it, in a round about way, does something like this:
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
try:
from greenlet import get_current as get_ident
except ImportError:
try:
from thread import get_ident
except ImportError:
from _thread import get_ident
connection_uri = 'postgresql://postgres:@localhost:5432/db'
engine = create_engine(connection_uri)
session_factory = sessionmaker(bind=engine)
session_cls = scoped_session(session_factory, scopefunc=get_ident)
session = session_cls()
Would this work for falcon? Will the get_ident
func "do the right thing" when using gunicorn?
resource.session.close()
orresource.session.remove()
? – Rarity