多进程、多线程加速(python)
• 前言
• 一、多线程加速
• 二、多进程加速
前言
一、多线程加速
import os
import threading
class myThread(threading.Thread):
def __init__(self,threadID,fileName):
super(myThread, self).__init__()
self.threadID = threadID
self.fileName = fileName
def run(self):
analyze(self.fileName) #analyse 为需要加速的函数
def threadDAOSTORM():
Input_file1 = FileName1
Input_file2 = FileName2
# 创建线程
thread1 = myThread(1, fileName=fileName1).run()
thread2 = myThread(2, fileName=fileName2).run()
thread1.start()
thread2.start()
if __name__ == '__main__':
threadDAOSTORM()
二、多进程加速
import os
import multiprocessing