多任务操作数据库时:2006, 'MySQL server has gone away'
来源:互联网 发布:mac玩fifaonline3发烫 编辑:程序博客网 时间:2024/05/22 08:21
查到Django官网中:https://code.djangoproject.com/ticket/21597
这不是数据库的问题。
If you hit this problem and don't want to understand what's going on, don't reopen this ticket, just do this:
RECOMMENDED SOLUTION: close the connection with
from django.db import connection
connection.close()
when you know that your program is going to be idle for a long time.
CRAPPY SOLUTION: increase wait_timeout so it's longer than the maximum idle time of your program.
In this context, idle time is the time between two successive database queries.
def main():
q = Queue()
p_1 = Process(target=func1, args=(selected, q))
p_2 = Process(target=func2, args=(request, q))
p_1.start()
p_2.start()
q.put(2)
return执行过程:
1)main:开启两个进程;往队列q里写入2;return
2)func1 和 func2 开始while循环,
func1先从q中读到2,于是执行func11,
func11之后往q中写3;
func2在1秒后开始从q中读到3,开始执行func22。def func1(dc_id, q=None):
while 1:
value = q.get(True)
time.sleep(1)
if value == 2:
func11(dc_id) # 操作数据库
q.put(3)
breakdef func2(request, q):
while 1:
time.sleep(1)
value = q.get(True)
if value == 3:
func22(request) # 操作数据库
breakdef func11(dc_id):
if not is_connection_usable():
connection.close()
...操作数据库...def func22(dc_id):
if not is_connection_usable():
connection.close()
...操作数据库...from django.db import connection
def is_connection_usable():
try:
print 'connection', connection.connection.ping()
except:
return False
else:
return True
q = Queue()
p_1 = Process(target=func1, args=(selected, q))
p_2 = Process(target=func2, args=(request, q))
p_1.start()
p_2.start()
q.put(2)
return执行过程:
1)main:开启两个进程;往队列q里写入2;return
2)func1 和 func2 开始while循环,
func1先从q中读到2,于是执行func11,
func11之后往q中写3;
func2在1秒后开始从q中读到3,开始执行func22。def func1(dc_id, q=None):
while 1:
value = q.get(True)
time.sleep(1)
if value == 2:
func11(dc_id) # 操作数据库
q.put(3)
breakdef func2(request, q):
while 1:
time.sleep(1)
value = q.get(True)
if value == 3:
func22(request) # 操作数据库
breakdef func11(dc_id):
if not is_connection_usable():
connection.close()
...操作数据库...def func22(dc_id):
if not is_connection_usable():
connection.close()
...操作数据库...from django.db import connection
def is_connection_usable():
try:
print 'connection', connection.connection.ping()
except:
return False
else:
return True
0 0
- 多任务操作数据库时:2006, 'MySQL server has gone away'
- mysql操作错误server has gone away
- python 操作数据库 OperationalError: (2006, 'MySQL server has gone away') 解决方法
- 2006 - MySQL server has gone away
- MySQL server has gone away (2006) 排查
- #2006 – MySQL server has gone away
- #2006 - MySQL server has gone away
- [Err] 2006 - MySQL server has gone away
- 2006 - MySQL server has gone away
- 2006 - MySQL server has gone away
- 2006 - MySQL server has gone away
- OperationalError: (2006, 'MySQL server has gone away')
- MySQL server has gone away
- MySQL server has gone away
- MySQL server has gone away
- MySQL server has gone away
- MySQL server has gone away
- MySQL server has gone away
- springMVC+spring+mybatis 开发http接口服务端(1. ssm框架搭建)
- iOS WebView不响应input标签
- J2EE验证码图片如何生成和点击刷新验证码
- cordova开发自定义插件
- iOS AFN框架简单使用
- 多任务操作数据库时:2006, 'MySQL server has gone away'
- 零基础HTML及CSS编码练习(一)
- perl pod文档使用 =head =cut =pod pod2text 实现程序usage说明
- HTTP 1.1与HTTP 1.0的比较
- 向升序排列的单链表中插入一个值,要求插入后仍为升序链表
- GObject 学习笔记汇总---12
- java中的存储区域
- CSS基础学习2-CSS设置颜色与背景
- 安装破解torando记录