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

[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的问题了。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容