我想知道在哪里创建一个用于 falcon 的范围会话的最佳位置。
通过阅读 flask-sqlalchemy 代码,它以一种大致的方式执行以下操作:
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()
这对猎鹰有用吗?get_ident
使用 gunicorn 时 func会“做正确的事”吗?