python 多线程_thread
阅读原文时间:2023年07月08日阅读:3

import _thread
import time

def print_time(threadName, delay, iterations):
start = int(time.time())
for i in range(,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, , ))
_thread.start_new_thread(print_time, ("Fizz", , ))
_thread.start_new_thread(print_time, ("Buzz", , ))
except:
print ("Error: unable to start thread")

while :
pass

demo2

import _thread
import time

def print_time(threadName, delay, iterations):
start = int(time.time())
for i in range(,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, , ))
_thread.start_new_thread(print_time, ("Fizz", , ))
_thread.start_new_thread(print_time, ("Buzz", , ))
except:
print ("Error: unable to start thread")

print("complete!")