jackpieno

碼農thread

Aug 9th, 2021
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. #匯入 線呈
  2. import threading
  3. #匯入 時間
  4. import time
  5.  
  6.  
  7. class TimerClass(threading.Thread):
  8.     #self 自身屬性 , Trhread 創建一個Thread , i 幾秒重新啟動 , target 任務
  9.     def __init__(self,Tthread = threading.Thread,i=1,target =None):
  10.         threading.Thread.__init__(self)
  11.         self.i = i
  12.         self.target = target
  13.         self.event = threading.Event()
  14.     #執行
  15.     def run(self):
  16.         while not self.event.is_set():
  17.             self.target()
  18.             self.event.wait(self.i)
  19.     #停止
  20.     def stop(self):
  21.         self.event.set()
Add Comment
Please, Sign In to add comment