Python使用SQLAlchemy+多线程报错
SAWarning: Usage of the ‘Session.add()’ operation is not currently supported
分析原因:多个线程共享了全局session
Session = scoped_session(sessionmaker(bind=engine))
session = Session()
def thread_task(name):
session.add(name=name)
session.commit()
然后多个线程共享了这个session.
修改代码
Session = scoped_session(sessionmaker(bind=engine))
def thread_task(name):
session = Session()
session.add(name=name)
session.commit()