只是按照一个教程,并据我所知完全复制它,但我的根本不打印任何东西,它应该显然从每个功能打印,但我似乎没有得到任何回报,不知道为什么?
#!/usr/bin/env python
import thread
import time
import random
def runOften(threadName, sleepTime):
while 1 < 2:
time.sleep(sleepTime)
print "%s" %(threadName)
def runLessOften(threadName, sleepTime):
while 1 < 2:
time.sleep(sleepTime)
print "%s" %(threadName)
def runRandomly(threadName, sleepTime):
while 1 < 2:
time.sleep(sleepTime)
print "%s" %(threadName)
try:
thread.start_new_thread(runOften, ("Often Runs", 2))
thread.start_new_thread(runLessOften, ("Less Often Runs!", 2))
thread.start_new_thread(runRandomly, ("Fast and random", random.random()))
except Exception, e:
print str(e)
Run Code Online (Sandbox Code Playgroud)