python 多线程_thread

 

import _thread
import time

def print_time(threadName, delay, iterations):
    start = int(time.time())
    for i in range(0,iterations):
        time.sleep(delay)
        seconds_elapsed = str(int(time.time()) - start)
        print (threadName if threadName else seconds_elapsed)

try:
    _thread.start_new_thread(print_time, (None, 1, 10))
    _thread.start_new_thread(print_time, ("Fizz", 3, 3))
    _thread.start_new_thread(print_time, ("Buzz", 5, 3))
except:
    print ("Error: unable to start thread")

while 1:
    pass

demo2

import _thread
import time

def print_time(threadName, delay, iterations):
    start = int(time.time())
    for i in range(0,iterations):
        time.sleep(delay)
        seconds_elapsed = str(int(time.time()) - start)
        print (threadName if threadName else seconds_elapsed)

try:
    _thread.start_new_thread(print_time, (None, 1, 10))
    _thread.start_new_thread(print_time, ("Fizz", 3, 3))
    _thread.start_new_thread(print_time, ("Buzz", 5, 3))
except:
    print ("Error: unable to start thread")

print("complete!")

 

posted @ 2019-06-21 09:32  anobscureretreat  阅读(129)  评论(0编辑  收藏  举报