我需要从mysql数据库中读取行并通过套接字发送到第二台服务器
现在我的代码是这样的:
首先,我从数据库中读取一条记录:
#main
while True:
cursor.execute("UPDATE `row_sent` SET `result`='pending' WHERE result='new' order by rsid DESC LIMIT 1;")
cursor.execute("select * from row_sent WHERE `result`='pending' limit 1;")
if cursor.rowcount>0 :
waitedSig = cursor.fetchone()
cursor.execute("UPDATE `row_sent` SET `result`='pending' WHERE `rsid`='"+ format(waitedSig[0]) +"' limit 1;")
t = threading.Thread(target=sendData , args=((waitedSig),))
t.start()
time.sleep(0.1)
这时我得到了一条记录并将其状态设置为“待处理”
然后通过套接字进行传输
def sendData(sig):
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = clientsocket.connect(('xxx.xxx.xxx.xxx' , xxxxx ))
clientsocket.send( sig[0] + sig[1] )
data = clientsocket.recv(1024)
clientsocket.close()
最终更新行驴success
cursor.execute("UPDATE `row_sent` SET `result`='success' WHERE `rsid`='"+ format(waitedSig[0]) +"' limit 1;")
此脚本正在运行,但速度确实很慢 看来它只是在最后一个套接字完成后创建一个套接字! 我如何改善我的表现?!