I’m trying to create a daemon thread under Windows, but I have no clue what am I doing wrong. The code below is acting as a normal thread: I don’t see “End run” written to the console. Any suggestions?
def start(self):
self.isrunning = True
self.thread = threading.Thread(name="GPS Data", target=self.thread_run)
self.thread.setDaemon(True)
self.thread.run()
print "End Run"
def thread_run(self):
while self.isrunning:
data = self.readline()
print(data)
The following:
should read:
Otherwise,
thread_run()is getting called in the context of the current thread, and not in the context of a new thread.The
thread_run()function never returns (becauseself.isrunningnever changes), and the code never reaches theprintstatement.