私はPythonが初めてです。これは私のコードです:
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()
コードをコピーして Python コマンド ライン プロンプトに貼り付けたところ、次の結果が得られました。
ご覧のとおり、2 つのスレッドは既に完了していますが、プログラムは終了していないようです (コマンド プロンプトが返されませんでした)。スレッドをプロパティ終了しなかった私のコードに関連していると思います。本当?この問題を修正するにはどうすればよいですか? ありがとう。