|
用以下代码启动多线程,如果已经启动了多个线程,比如4个,现在想要与其中一个线程做用户交互,应该怎么写代码?
class timer(threading.Thread): #The timer class is derived from the class threading.Thread
def __init__(self, num, interval):
threading.Thread.__init__(self)
self.thread_num = num
self.interval = interval
self.thread_stop = False
self.thread_pause = False
self.count = 0
self.showtimes = 0
def run(self): #Overwrite run() method, put what you want the thread do here
while not self.thread_stop:
time.sleep(self.interval)
self.count = self.count + self.thread_num
def stop(self):
self.thread_stop = True
|
|