7
Tôi tự hỏi nơi tốt nhất sẽ là tạo một phiên scoped để sử dụng trong falcon.SQLAlchemy và Falcon - khởi tạo phiên
Từ đọc mã bình-SQLAlchemy, nó, trong một vòng khoảng cách, làm điều gì đó như thế này:
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()
tác phẩm này với ưng Sẽ? get_ident
func "làm điều đúng" khi sử dụng gunicorn?
Điều này thực sự hữu ích. Một câu hỏi nhanh, đó có phải là 'resource.session.close()' hay 'resource.session.remove()'? – misakm
Không, nó phải là 'Session.remove()' theo http://docs.sqlalchemy.org/en/rel_1_1/orm/contextual.html#using-thread-local-scope-with-web-applications. –