我在PyCharm中有这个代码。我点击“播放”来运行代码,它工作正常,但如果我点击两次或更多,有时不起作用,程序在行中输入死锁:
f=cnx_cursor1.fetchall()
代码:
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import mysql.connector
import time
tik = time.time()
configDB = {
'user': '****',
'password': '****',
'host': '****',
'database': '****',
'raise_on_warnings': True,
'charset': 'utf8',
'use_unicode': True,
'collation': 'utf8_general_ci'
}
cnx = mysql.connector.connect(**configDB)
cnx_cursor1 = cnx.cursor(dictionary=True)
sql1 = "SELECT E.*, " + \
" ((E.statusNumber & 4278190080) >> 24) as s1, " + \
" ((E.statusNumber & 0016711680) >> 16) as s2, " + \
" ((E.statusNumber & 0000065280) >> 08) as s3, " + \
" ((E.statusNumber & 0000000255) >> 00) as s4 " + \
" from EUser as E order by E.user_id, E.project;"
cnx_cursor1.execute(sql1)
print "After Execute:", "{:3.10f}".format(time.time()-tik), "s"
f=cnx_cursor1.fetchall()
print "After Fetch:", "{:3.10f}".format(time.time()-tik), "s"
ret = []
for l in f:
print "user_id:", l["user_id"], "s1:", l["s1"], "s2:", l["s2"], "s3:", l["s3"], "s4:", l["s4"]
if l["statusPhoto"] == 0:
pass
time.sleep(1)
cnx_cursor1.close()
cnx.close()
print "END:", "{:3.10f}".format(time.time()-tik), "s"
任何人都可以帮助我?
这个问题是MySQL的连接吗?
由于
答案 0 :(得分:1)
FetchAll策略存在一些问题(我遇到过)
以下是我要对此进行问题排查的方法
我希望这会有所帮助