【发布时间】:2014-01-15 16:34:22
【问题描述】:
我已经为线程编写了非常基本的 Python 代码...
import time
import thread
def print_hello(name,delay):
while 1:
print name
time.sleep(delay)
try:
thread.start_new_thread(print_hello, ("frist",1,))
thread.start_new_thread(print_hello, ("second",2,))
except:
print "unable to start thread"
time.sleep(4)
print "hello"
哪个输出是:
second
frist
frist
second
frist
frist
hello
例外:
Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr
我的查询是:
- 为什么第二次来第一次?
- 为什么会出现异常?
【问题讨论】:
-
有些人在遇到问题时会想“我会使用线程”。然后两个他们有问题。
标签: python multithreading