Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python how to restart thread

# You can not restart a thread in python
# However you can make sure it stays alive forever
# If threads ending is a problem just loop them forever

# Example:
import threading
import time

class mythreader(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.running = True
        self.start()
        
    def run(self):
        mycounter = 0
        while self.running:
			do_some_cool_stuff()
            time.sleep(2)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #restart #thread
ADD COMMENT
Topic
Name
4+3 =