赞
踩
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 def worker1(fileName): #进程1 analyze(fileName) #analyse为需要加速的函数 def worker2(fileName): #进程2 analyze(fileName) #analyse为需要加速的函数 def Multithread_fun(): Input_file1 = FileName1 Input_file2 = FileName2 # 创建进程 process1 = multiprocessing.Process(target=worker1, args=(Input_file1) process2 = multiprocessing.Process(target=worker2, args=(Input_file2) process1.start() #开启 process2.start() process1.join() #同步 process2.join() if __name__ == '__main__': Multithread_fun()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。