python how to restart thread

Solutions on MaxInterview for python how to restart thread by the best coders in the world

showing results for - "python how to restart thread"
Erica
23 Oct 2016
1# You can not restart a thread in python
2# However you can make sure it stays alive forever
3# If threads ending is a problem just loop them forever
4
5# Example:
6import threading
7import time
8
9class mythreader(threading.Thread):
10    def __init__(self):
11        threading.Thread.__init__(self)
12        self.setDaemon(True)
13        self.running = True
14        self.start()
15        
16    def run(self):
17        mycounter = 0
18        while self.running:
19			do_some_cool_stuff()
20            time.sleep(2)
similar questions
queries leading to this page
python how to restart thread