I'm new in Python. This is my code:
import logging
logging.basicConfig(level = logging.DEBUG, format = "[%(levelname)s] (%(threadName)-10s) %(message)s")
import threading
import time
def thread1():
for i in range(0, 10, 2):
logging.debug(i)
time.sleep(1)
def thread2():
for i in range(10, 20):
logging.debug(i)
time.sleep(1)
t1 = threading.Thread(name = "thread1", target = thread1)
t1.setDaemon(True)
t1.start()
t2 = threading.Thread(name = "thread2", target = thread2)
t2.setDaemon(True)
t2.start()
When I copied the code and pasted it into a python command line prompt, I got the following result.
As you can see, the 2 threads already completed but it seems the program does not exit ( I did not get the command prompt back). I think it relates to my code that did not property end the threads. Is that true? How to fixed this issue? Thanks.