Python 可以通过 threading module 来创建新的线程,然而在创建线程的父线程关闭之后,相应的子线程可能却没有关闭,这可能是因为代码中没有使用setDaemon(True)函数。接下来,使用一个例子来说明:

import threading

def prt_hello() :
    while 1 :
        print 'hello'

if __name__ == '__main__' :
    t = threading.Thread(target=prt_hello)
    t.setDaemon(True)
    t.start()
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。