#!/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