import time,threading class URMonitor: def checkThread(self,threads): for i in range(len(threads)): threadName = threads[i].name if threads[i].is_alive(): print("Thread is alive:",threadName) else: print("Thread is stopped:",threadName) if threadName == 'monitor': print("restart monitor") t = threading.Thread(target=self.monitorNotice, name='monitor') t.start() threads[i] = t elif threadName == 'order': print("restart order") t = threading.Thread(target=self.order, name='order') t.start() threads[i] = t def moniotr(self): print("monitor start") def order(self): print("order start") def main(self): threads = [] tMonitor = threading.Thread(target=self.monitorNotice, name='monitor') tMonitor.start() threads.append(tMonitor) tOrder = threading.Thread(target=self.order, name='order') tOrder.start() threads.append(tOrder) while True: self.checkThread(threads) time.sleep(30) if __name__ == '__main__': m = URMonitor() m.main()