I have a class that is calling a thread like below.
import threading
import time
class ThreadingExample:
def __init__(self):
thread = threading.Thread(target=self.run, args=())
thread.daemon = True
thread.start()
def run(self):
# Do something
print('Doing something important in the background')
time.sleep(100)
# a print statement will not be executed here even with flush=True
example = ThreadingExample()
However, sleep
is not working. The thread is executed since the first print in run() is being printed however the program terminates instantly after the print statement.
For testing purposes I inserted another print statement after the sleep(100) and that does not print either. what is the problem here?
This code should be completed and reproducable