在Windows 7 Pro 64位上运行Python 3.2。Python线程支持脚本的其余部分
好的我在这里有一些非常基本的代码,这只是表现得不像我想要的那样。
#!/usr/bin/env python
import time
import threading
def shutdown(sleeptime):
time.sleep(sleeptime)
print('I have executed')
threading.Thread(target = shutdown(5)).start()
print('I go first')
的想法是,脚本运行时,它开始其休眠5秒钟,然后打印出“我已执行”的线程。与此同时,脚本继续前进并打印出“我先走了”。
实际情况是脚本启动线程,一切都等待它完成,然后继续。显然,我不是在做正确的线程,但我无法找到线程的简单示例与Python 3
谢谢,优秀和良好解释的答案! – Sparc 2012-03-08 21:42:57