马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import threading # 线程模块
import time
def eat_breakfast():
time.sleep(3)
print("You eat breakfast")
def drink_coffee():
time.sleep(4)
print("You drank coffee")
def study():
time.sleep(5)
print("You finish studying")
x = threading.Thread(target=eat_breakfast, args=())
x.start()
y = threading.Thread(target=drink_coffee, args=())
y.start()
z = threading.Thread(target=study, args=())
z.start()
x.join() # thread synchronization(线程同步)
y.join() # thread synchronize and join(线程同步并加入)
z.join()
# eat_breakfast()
# drink_coffee()
# study()
print(threading.active_count()) # 函数名活动计数
print(threading.enumerate()) # 函数名枚举
print(time.perf_counter()) # performance counter function(函数名性能计数器)
console window:
You eat breakfast
You drank coffee
You finish studying
1
[<_MainThread(MainThread, started 14744)>]
9517.6617491 |