帮我看看这个python 是为什么

#coding=utf-8

#!/usr/bin/python


import thread

import time


# 为线程定义一个函数

def print_time( threadName, delay):

   count = 0

   while count < 5:

      time.sleep(delay)

      count += 1

      print "%s: %s" % ( threadName, time.ctime(time.time()) )


# 创建两个线程

try:

   thread.start_new_thread( print_time, ("Thread-1", 2, ) )

   thread.start_new_thread( print_time, ("Thread-2", 4, ) )

except:

   print "Error: unable to start thread"


while 1:

   pass

为毛去掉

while 1:   
    pass

线程定义的函数 print_time 就不执行了呢


jeck猫
浏览 372回答 1
1回答

HUH函数

因为创建的线程是主进程的子线程啊,吧while无限循环去掉了,主进程一建立子线程就立刻结束,那么子线程也会立刻被销毁。可以了解下线程的生命吧~
打开App,查看更多内容
随时随地看视频慕课网APP