系统win764位系统,Python2.7版本,同样64位,MySQL-python1.2.364位。测试代码#-*-coding:utf-8-*-importsys,MySQLdb,threading,random,timereload(sys)sys.setdefaultencoding('utf...
系统win7 64位系统,Python2.7版本,同样64位,MySQL-python1.2.3 64位。测试代码
# -*- coding: utf-8 -*-
import sys,MySQLdb,threading,random,time
reload(sys)
sys.setdefaultencoding('utf-8')
def test():
for az in range(1,100):
time.sleep(random.randint(1,5))
cur1.execute('insert into test1 (test1)values (%s)', str(random.randint(1,100)))
conn = MySQLdb.connect(host='localhost', user='test', passwd='test', db='test1')
conn.ping(True)
cur1 = conn.cursor()
th=[]
for a in range(50):
th.append(threading.Thread(target=test,args=()))
for aa in th:
aa.start()
for aaa in th:
aaa.join()
抛出的异常
Exception in thread Thread-5:
Traceback (most recent call last):
File "D:\python\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "D:\python\lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "G:/source/python/test1.py", line 10, in test
cur1.execute('insert into test1 (test1)values (%s)', str(random.randint(1,100)))
File "D:\python\lib\site-packages\MySQLdb\cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "D:\python\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (2013, 'Lost connection to MySQL server during query')
不一定是哪个线程抛,但是都是一样的异常OperationalError: (2013, 'Lost connection to MySQL server during query')这句话,网上说的改数据库配置文件的方法都试过了,木有用。MySQL-python最新版还没有64位的,源码还编译失败、请问这个应该怎么处理?
展开