Python 多线程运行,可是为什么是Thread-2先执行
本文介绍了Python 多线程运行,可是为什么是Thread-2先执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import thread
import time
def print_time(threadName, delay, count):
print "%s: %s %s \n" % (threadName, time.ctime(time.time()), str(count))
count = count
while count < 5:
time.sleep(delay)
count += 1
print "%s: %s %s" % (threadName, time.ctime(time.time()), str(count))
try:
thread.start_new_thread(print_time, ("Thread-1", 1, 0))
thread.start_new_thread(print_time, ("Thread-2", 3, 0))
except:
print "Error: unable to start thread"
while 1:
pass
运行结果:
解决方案
随机的,但是python不推荐thread模块,建议用threading
这篇关于Python 多线程运行,可是为什么是Thread-2先执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文