美文网首页
[django] Exception Value: Datab

[django] Exception Value: Datab

作者: 饶一熊 | 来源:发表于2020-03-26 11:40 被阅读0次

[django] Exception Value: DatabaseWrapper objects created in a thread can only be used in that same thread.

问题描述:

使用django框架实现的web后端服务,使用orm语句插入数据时报错,报错信息如下;

image-20200326101024514

django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias ‘default’ was created in thread id 8576 and this is thread id 11652

报错代码位置如图。

image-20200326101256272

问题分析:

项目本地调试是完全ok的,部署到服务器上就出现这个问题。

1.好了开始对代码做各种排查,发现并没有问题。

2.然后开始各种github搜索问题,这个问题出现的频率也不高,最终找到两个比较符合说法

问题解决

突然想到,我们项目开始使用uwsgi启动服务的,也是在问题发生前换成了gunicorn部署,于是赶紧换回uwsgi来启动服务,成功了!!

查看了gunicorn的配置文件,发现里面也调用了gevent的模块。

image-20200326113005253

这样的话,大概率就是gevent的问题了。

相关文章

网友评论

      本文标题:[django] Exception Value: Datab

      本文链接:https://www.haomeiwen.com/subject/dugquhtx.html