[django] Exception Value: DatabaseWrapper objects created in a thread can only be used in that same
2020-04-01 13:02
1221 查看
[django] Exception Value: DatabaseWrapper objects created in a thread can only be used in that same thread.
问题描述:
使用django框架实现的web后端服务,使用orm语句插入数据时报错,报错信息如下;
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
报错代码位置如图。
问题分析:
项目本地调试是完全ok的,部署到服务器上就出现这个问题。
1.好了开始对代码做各种排查,发现并没有问题。
2.然后开始各种github搜索问题,这个问题出现的频率也不高,最终找到两个比较符合说法
- gevent模块开线程的冲突:https://blog.csdn.net/u014007037/article/details/86645862
- gunicorn起服务的冲突:https://github.com/benoitc/gunicorn/issues/927
问题解决
突然想到,我们项目开始使用uwsgi启动服务的,也是在问题发生前换成了gunicorn部署,于是赶紧换回uwsgi来启动服务,成功了!!
查看了gunicorn的配置文件,发现里面也调用了gevent的模块。
这样的话,大概率就是gevent的问题了。
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 多线程下,Python Sqlite3报[SQLite objects created in a thread can only be used...]问题
- Python SQLite3的问题sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in th
- An explicit value for the identity column in table can only be specified when a column list is used
- CalledFromWrongThreadException:Only the original thread that created a view hierarchy can touch its
- An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
- calledfromwrongthreadexception only the original that created a view hierarchy can touch its views
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views. .
- android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRo
- only the original thread that created a view hierarchy can touch its views解决方案
- 关于Only the original thread that created a view hierarchy can touch its views的解决方案
- 开发中错误记录:解决:Only the original thread that created a view hierarchy can touch its views.
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android子线程控制UI线程,以防:Only the original thread that created a view hierarchy can touch its views.
- 关于Only the original thread that created a view hierarchy can touch its views的解决方案
- 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a v
- Only the original thread that created a view hierarchy can touch its views.
- Hardware acceleration can only be used with a single UI thread