【发布时间】:2017-07-05 12:23:40
【问题描述】:
from threading import Thread, current_thread
def hello():
print("hello, world")
t = threading.Timer(3.0, hello)
t.start()
print current_thread().name
hello()
这将每 3 秒定期创建一个新线程。我想知道创建的线程是否过期,然后会再次创建新线程。?我可以看到线程名称为“Thread-1”、“Thread-2”、“Thread-3”等被创建。我想知道“Thread-1”是否最终会退出,然后创建一个新线程,即“Thread-2”或仍然“Thread-1”将保持活动状态。请帮忙。
【问题讨论】:
-
线程将首先调用函数
hello,然后 - 完成后 - 退出。这意味着在t.start()语句之后有两个线程处于活动状态:一个是刚刚创建的,另一个是“创建者”。在hello返回后,只有一个线程处于活动状态。
标签: python multithreading python-2.7