多线程执行SQL文件

多线程执行SQL文件

# -*- coding: utf-8 -*-
"""
@Time    : 2021/7/15 16:04
@Author  : Little Duo
@File    : 多线程执行SQL文件.py
"""

# -*- coding: utf-8 -*-
import queue
import threading
import os

q = queue.Queue()


class MyThread(threading.Thread):
    def __init__(self, func):
        threading.Thread.__init__(self)
        self.func = func

    def run(self):
        try:
            self.func()
        except Exception as e:
            print(e)

            
def main():
    threads = []
    for row in sqlFilePathList:
        q.put(row)
    for i in range(threadNum):
        thread = MyThread(worker)
        thread.start()
        threads.append(thread)
    for thread in threads:
        thread.join()


def worker():
    while not q.empty():
        sqlFilePath = q.get()
        连接mysql执行sql文件中的SQL语句


if __name__ == '__main__':
    sqlFilePathList = [] # [SQL文件的路径,...]
    threadNum = 100 # 线程数量
    main()

posted @ 2023-02-28 14:34  LittleDuo  阅读(59)  评论(0)    收藏  举报