What's the recommended scoped_session usage pattern in a multithreaded sqlalchemy webapp?

后端 未结 2 1502
情歌与酒
情歌与酒 2021-01-31 17:30

I\'m writing an application with python and sqlalchemy-0.7. It starts by initializing the sqlalchemy orm (using declarative) and then it starts a multithreaded web server - I\'m

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 17:58

    You don't need to create a scoped session if you create new session for each request and each request is handled by single thread.

    You have to call s.commit() to make pending objects persistent, i.e. to save changes into database.

    You may also want to close session by calling s.close().

提交回复
热议问题