什么时候线程的运行命令在Python中终止

时间:2015-09-26 00:34:13

标签: python multithreading

阅读this

  

一旦线程的活动开始,线程就被认为是“活着的”。当它的run()方法终止时,它会停止活动 - 通常,或者通过引发未处理的异常。

these answers,我仍然不确定Python线程何时“死”。例如,如果我调用类似这样的线程:

def preparemessage():
    print('test')

def notify(message):
    thread = threading.Thread(target=preparemessage, args=(message))
    thread.start()

线程是否会在打印“test”后终止?

即。当他们负责完成的事情时,这些线程是否会终止?我意识到这不是解释事情的好方法,但我不知道怎么说。有没有简单的方法来解释这个?

1 个答案:

答案 0 :(得分:1)

是。一旦目标函数完全执行完毕或发生了一些错误,线程将被终止。

相关问题