In flask-sqlalchemy, I use db.session to gain batch tasks, and commit() all changes on these tasks' status, then I start with multiprocess to perform tasks. My question is the task in session of main thread which is commited, after starting multiprocess, each task shares the session from the main thread and lead to errors which i have attached in this post. Because entire project uses db.session, how can I fix this problem to minimize the changes.
[original code][1]
[problem screenshot1][2]
[problem screenshot2][3]