在以下范例,python3.x的多线程程序中,while 1: pass 这个语句有什么作用?


范例:
#!/usr/bin/python3

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: 无法启动线程")

while 1:
pass

呼啦一阵风
浏览 294回答 1
1回答

烙印99

pass 在python 中有占位的作用,也就是说什么都不运行,还有就是while 有阻塞主线程的做作用,如果你在while 里面加个条件,条件成立,都还没执行完,就不往下运行。先把上面的线程执行。
打开App,查看更多内容
随时随地看视频慕课网APP