I'm using Portable Python 3.9.4 x64 on Windows and everytime I'm calling the time.sleep(...)-method the Thread exits and won't return:
import threading
import time
threads = []
print ("hello")
class myThread(threading.Thread):
def __init__(self, i):
threading.Thread.__init__(self)
self.i = i
def run(self):
print ("i = ", self.i)
for j in range(0, self.i):
print ("i: ", i,"j = ",j)
time.sleep(5)
for i in range(1,4):
thread = myThread(i)
thread.daemon = False
thread.start()
My Output is:
hello
i = 1
i: 1 j = 0
i = 2
i: 2 j = 0
i = 3
i: 3 j = 0
If I'm using shorter delays like time.sleep(0.05)
then I get more values for j, but still not all of them.
So I guess all threads are killed, because the main-thread finishes. But how can I keep the threads running?
The daemon-attribute seems not to change anything...