pytjon多线程执行mysql_使用Python的多线程MySql插入

下面是我用来上传数据到MySQL的多线程脚本。使用线程执行多个插入,听起来不错。在

但是性能没有提高。MySql被设置为接受多个连接,但是当我检查进程列表时,我没有看到我期望的5-10个连接。cxn字符串是

有办法解决这个问题吗?在import sys, threading, Queue pyodbc

class WorkerThread(threading.Thread):

def __init__(self, queue):

threading.Thread.__init__(self)

self.queue = queue

def run(self):

while 1:

try: # take a job from the queue

id, null, null2, null3 = self.queue.get_nowait()

except Queue.Empty:

raise SystemExit

In Here I have MySQl connecctions

*** cxn = pyodbc.connect('DSN=MySQL;PWD=MLML;Option=3')

csr = cxn.cursor()

typical insert , selects Updates

if __name__ == '__main__':

connections = 25

# build a queue with tuples

queue = Queue.Queue()

queue.put(row[:3])

# print queue

threads = []

for dummy in range(connections):

t = WorkerThread(queue)

t.start()

threads.append(t)

# wait for all threads to finish

for thread in threads:

thread.join()

Cxn字符串设置在顶部。我曾尝试在Worker线程中使用cxn字符串,但是有很多改进。在工作线程中,MySQL是单向的。表被截断然后插入。通常每个工人只有一张桌子。它的速度很快,而且系统是本地的。但我看不到很多联系,我希望看到。在

队列=30-400个项目。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值