def main(): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as soc: soc.bind((HOST, PORT)) soc.listen(10) while True: conn, address = soc.accept() myThread.myThread(conn, address, dir).start()
def run(self): try: self.mThread = myThread() self.mThread.addThread('onlineClf', self.onlineClf, 0) #加入在线识别动作线程 self.mThread.addThread('getData', self.myoRun, 0) #加入数据采集的线程 self.mThread.runThread() except KeyboardInterrupt: self.mMyo.safely_disconnect() self.mThread.forcedStopThread()
def parallel_Estimate(): threads = {} totalTime = 0 Q = multiprocessing.Queue() for iter in range(0, VALS.iters): start = timeit.default_timer() print("Sampling: Iteration Number: " + str(iter + 1)) for i in range(0, VALS.num_Threads): threads[i] = myThread.myThread(i + 1, "Thread-" + str(i + 1), Q) for i in range(0, VALS.num_Threads): threads[i].start() temp_NPK = numpy.zeros([VALS.n_NP, VALS.K], dtype=float) temp_VPK = numpy.zeros([VALS.n_VP, VALS.K], dtype=float) temp_NPK_Sum = numpy.zeros([VALS.K], dtype=float) temp_VPK_Sum = numpy.zeros([VALS.K], dtype=float) track = 0 while 1: if track == VALS.num_Threads: break else: track += 1 print("Tracking:" + str(track)) vals_dict = Q.get() ID = vals_dict['ID'] for ci in range(vals_dict['startCI,' + ID], vals_dict['endCI,' + ID]): VALS.z_CI[ci] = vals_dict['z_CI,' + ID][ci] VALS.n_CIK[ci] = vals_dict['n_CIK,' + ID][ci] for trp in range(vals_dict['startTrp,' + ID], vals_dict['endTrp,' + ID]): VALS.z_Trp[trp] = vals_dict['z_Trp,' + ID][trp] VALS.n_TK[trp] = vals_dict['n_TK,' + ID][trp] for doc in range(vals_dict['startDoc,' + ID], vals_dict['endDoc,' + ID]): VALS.zDocNP[doc] = vals_dict['zDocNP,' + ID][doc] VALS.zDocVP[doc] = vals_dict['zDocVP,' + ID][doc] VALS.n_docK[doc] = vals_dict['n_docK,' + ID][doc] temp_NPK += vals_dict['n_NPK,' + ID] - VALS.n_NPK temp_VPK += vals_dict['n_VPK,' + ID] - VALS.n_VPK temp_NPK_Sum += vals_dict['n_NPK_sum,' + ID] - VALS.n_NPK_sum temp_VPK_Sum += vals_dict['n_VPK_sum,' + ID] - VALS.n_VPK_sum VALS.n_NPK += temp_NPK VALS.n_VPK += temp_VPK VALS.n_NPK_sum += temp_NPK_Sum VALS.n_VPK_sum += temp_VPK_Sum stop = timeit.default_timer() totalTime += stop - start print("Time Elapsed for Iteration-" + str(iter) + ": " + str(stop - start)) print("Total Estimating Time: " + str(totalTime))
def threadM(urls, function): for i, j, k, l in zip(urls[0::4], urls[1::4], urls[2::4], urls[3::4]): print(i, j, k, l) # 创建新线程 thread1 = myThread(i[1], 1, i, function) thread2 = myThread(j[1], 2, j, function) thread3 = myThread(k[1], 1, k, function) thread4 = myThread(l[1], 2, l, function) # 开启新线程 thread1.start() thread2.start() thread3.start() thread4.start() thread1.join() thread2.join() thread3.join() thread4.join() print("退出主线程")
def run(self): '''运行主程序''' try: self.mThread = myThread() self.mThread.addThread('setTheActionMain' , self.setTheActionMain , 0) self.mThread.addThread('getTheActionMain' , self.getTheActionMain , 0) self.mThread.addThread('getKeyValueMain' , self.getKeyValueMain , 0) self.mThread.runThread() except KeyboardInterrupt: print("DONE") self.bebop.disconnect() self.mThread.forcedStopThread()
def generate_threads(dataframeFilmes, listaDeIntervalos, listaDeFilmesLink, listaDeFilmesLinkInvalido): vetorDeThreads = [] contador = 0 for i in range(10): thread = myThread(1, "Thread-{}".format(i + 1), listaDeIntervalos[contador], listaDeIntervalos[contador + 1], dataframeFilmes, listaDeFilmesLink, listaDeFilmesLinkInvalido) vetorDeThreads.append(thread) contador = contador + 2 return vetorDeThreads
def run(self): global stopFlag try: self.mThread = myThread() self.mThread.addThread('setPic', targetFunc=self.setActionState, haveArgsFlag=1, args=(self.actionTime, self.restTime)) self.mThread.addThread('getData', self.myoRun, 0) #加入数据采集的线程 self.mThread.runThread() if stopFlag == True: self.mThread.stopThread() except KeyboardInterrupt: self.mMyo.safely_disconnect() print('Finished.')
def main(): nloops = randint(2,5) q = Queue(32) threads = [] for i in nfuncs: t = myThread(funcs[i],(q,nloops),funcs[i].__name__) threads.append(t) for i in nfuncs: threads[i].start() for i in nfuncs: threads[i].join() print('all done')
def main(): nloops = randint(2, 5) q = Queue(32) threads = [] for i in nfuncs: t = myThread(funcs[i], (q, nloops), funcs[i].__name__) threads.append(t) for i in nfuncs: threads[i].start() for i in nfuncs: threads[i].join() print 'ALL DONE'
def main(): thread_list = [] my_dict = {} my_dict[0] = obj.Object(0, 20) my_dict[1] = obj.Object(1, 50) my_dict[2] = obj.Object(2, 70) my_dict[3] = obj.Object(3, 40) # print(my_dict) #prve spustenie for key, value in my_dict.items(): t = Thread(target=value.getImage, ) t.start() # print(active_count()) thread_list.append(t) value.time += value.interval mainThread = myThread(my_dict) mainThread.start()
def main(): nfuncs = range(len(funcs)) print('-------single thread-----') for i in nfuncs: print('starting %s at:%s'% (funcs[i].__name__,ctime())) print(funcs[i](n)) print('%s finished at:%s'% (funcs[i].__name__,ctime())) print('======multiple threads======') threads = [] for i in nfuncs: t = myThread(funcs[i],(n,),funcs[i].__name__) threads.append(t) for i in nfuncs: threads[i].start() for i in nfuncs: threads[i].join() print(threads[i].getResult()) print('----====all done====----')
def main(): nfuncs = range(len(funcs)) print('*** single thread') for i in nfuncs: print('starting',funcs[i].__name__,'at:',ctime()) print(funcs[i](n)) print(funcs[i].__name__,'finished at:',ctime()) print('*** multiple thread') threads = [] for i in nfuncs: t = myThread(funcs[i],(n,),funcs[i].__name__) threads.append(t) for i in nfuncs: threads[i].start() for i in nfuncs: threads[i].join() print(threads[i].getResult()) print('all done!')
def prep_data(rooms=1, country='Macedonia', out_format=None): ''' Prepare data for saving :return: hotels: set() ''' offset = 15 session = requests.Session() parsed_html = get_booking_page(session, offset, rooms, country) all_offset = parsed_html.find_all( 'li', {'class': 'sr_pagination_item'})[-1].get_text() number = 0 threads = [] for i in range(int(all_offset)): offset += 15 t = myThread.myThread(session, offset, rooms, country, process_hotels) threads.append(t) for t in threads: t.start() for t in threads: t.join() hotels2 = hotels return hotels2
#!/usr/bin/env python # -*- coding:utf-8 -*- import time, os from myThread import myThread from utile import setting, tool if __name__ == '__main__': package = setting.package '''Start pulling hprof files on each device''' print("-------Start pulling hpro files-------") tool.del_data() #备份当日原始数据 threads = [] thread1 = myThread(setting.device_id, setting.data) thread1.start() # thread2 = myThread("PullHprof","C:\liuti\self\PerformaceTest\data") # thread2.start() threads.append(thread1) # threads.append(thread2) # while True: # print (thread1.isAlive()) # time.sleep(5) # for deviceid in deviceidlist: # thread = myThread() # threads.append(thread) # 开启新线程 # for thread in threads:
#!/usr/bin/python
if __name__ == '__main__': package = setting.package deviceidlist = getDeviceidList() date = time.strftime("%Y%m%d", time.localtime(time.time())) # global result_path result_path = "./output/" + date if not os.path.exists(result_path): os.makedirs(result_path) devicelist = getDeviceidList() threads = [] for deviceid in devicelist: thread = myThread(deviceid, result_path) threads.append(thread) for thread in threads: thread.start() for deviceid in deviceidlist: run_performance(10000) time.sleep(10) for thread in threads: thread.setPause(1)
exit(1) # Check for duplicate characters j = 0 for c in characters: if c == ch: j += 1 if j > 1: print("Error -> '" + characters + "' has duplicate characters!") exit(1) chars.append(ch) # Add upper case characters to list upChars = characters.upper() for ch in upChars: chars.append(ch) # Concat two lists into a single list chars = chars + staticChars # Starting the threads for i in range(startRange, endRange + 1): fileName = 'output/' + outputFileName.split(".")[0] + "-" + str( i) + "." + outputFileName.split(".")[1] mFile = open(fileName, 'w') mFile.write('') mFile = open(fileName, 'a') th = myThread(i, chars, mFile) th.start()