Python flask sqlalchemy使Postgres事务处于空闲状态
我正在使用flaskrestful、sqlalchemy、Postgres、nginx、uwsgi编写一个flaskapi。我是python的新手。这些是我的配置 数据库.py api.py 在这里,我先保存url,然后使用样板文件保存网站的所有内容 model.pyPython flask sqlalchemy使Postgres事务处于空闲状态,python,api,postgresql,sqlalchemy,flask,Python,Api,Postgresql,Sqlalchemy,Flask,我正在使用flaskrestful、sqlalchemy、Postgres、nginx、uwsgi编写一个flaskapi。我是python的新手。这些是我的配置 数据库.py api.py 在这里,我先保存url,然后使用样板文件保存网站的所有内容 model.py 因此,这段代码在本地运行得很好,但在生产环境中不起作用。因此,当我检查pag_stat_活动时,它会显示状态“idle in transaction”。应用程序挂起,然后我必须重新启动服务器。我不明白session.close()
因此,这段代码在本地运行得很好,但在生产环境中不起作用。因此,当我检查pag_stat_活动时,它会显示状态“idle in transaction”。应用程序挂起,然后我必须重新启动服务器。我不明白session.close()为什么不关闭池连接,为什么它使psql事务状态保持繁忙。伙计们,如果有任何帮助,我们将不胜感激。您将在课程结束前返回:
return "Data created "
session.close()
我认为返回内部最终可能也会吞掉异常。好吧,生产和本地开发之间的配置或版本是否有任何差异?除了我在本地和生产中使用的服务器之外,没有任何东西是相同的。好吧,有些东西必须是不同的,无论是包版本、环境变量、配置文件,网络设置方面的差异等等。为了准确地追踪什么,您可能需要一步一步地完成这个过程,并比较它在每一步中所做的工作。我认为堆栈溢出并不能真正帮助解决这个问题。
class Webcontent(Resource):
def post(self):
session=Session()
...assign some params...
try:
insert_data=Websitecontent(site_url,publisher_id)
session.add(insert_data)
session.commit()
Websitecontent.update_url(insert_data.id,session)
except:
session.rollback()
raise
finally:
return "Data created "
session.close()
else:
return "some value"
class Websitecontent(Base):
@classmethod
def update_url(self,id,session):
existing_record=session.query(Websitecontent).filter_by(id=int(id)).first()
data=Processing.processingContent(str(existing_record.url))
#boilerpipe processing the content here
#assigning some data to existing record in session
session.add(existing_record)
session.commit()
Websitecontent.processingWords(existing_record,session)
@classmethod
def processingWords(self,record,session)
...processing
Websitecontent.saveKeywordMapping(session,keyword_url,record)
@classmethod
def saveKeywordMapping(session,keyword_url,record)
session.commit()
session.close()
return "Data created "
session.close()