[django] Exception Value: DatabaseWrapper objects created in a thread can only be used in that same thread.
问题描述:
使用django框架实现的web后端服务,使用orm语句插入数据时报错,报错信息以下;git
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 11652github
报错代码位置如图。web
问题分析:
项目本地调试是彻底ok的,部署到服务器上就出现这个问题。django
1.好了开始对代码作各类排查,发现并无问题。后端
2.而后开始各类github搜索问题,这个问题出现的频率也不高,最终找到两个比较符合说法服务器
- gevent模块开线程的冲突:https://blog.csdn.net/u014007037/article/details/86645862
- gunicorn起服务的冲突:https://github.com/benoitc/gunicorn/issues/927
问题解决
忽然想到,咱们项目开始使用uwsgi启动服务的,也是在问题发生前换成了gunicorn部署,因而赶忙换回uwsgi来启动服务,成功了!!app
查看了gunicorn的配置文件,发现里面也调用了gevent的模块。框架
这样的话,大几率就是gevent的问题了。this