def doTrans(self, command): try: if self.isOpen >= 0: send_str = self.entrySend.get() self.showLog("超时时间:%s" % send_str) self.showLog("开始交易...") t = MyThread.myThread(command, self.dll) t.setDaemon(True) t.start() t.join() return t.get_result() else: self.showLog("串口没有打开") except Exception as e: print(e) self.showLog("发送失败")
import os import time import MyThread filePath = "Image//" MyThread.myThread.filePath = filePath now = 1 allImage = os.listdir(filePath) for image in allImage: if image.endswith((".png", ".jpg")): thread = MyThread.myThread(str(now), image, now) thread.start() now = now + 1 time.sleep(0.05)
import operations import time import MyThread start_time = time.perf_counter() for x in range(30): operations.random_numbers(1, 1000000) end_time = time.perf_counter() elapsed_time = end_time - start_time print("Without using thread library: " + str(elapsed_time)) start_time = time.perf_counter() for x in range(30): MyThread.myThread(x).start() end_time = time.perf_counter() elapsed_time = end_time - start_time print("Using thread library: " + str(elapsed_time))