#============1、多线程
#python的多线程是伪多线程,通过全局锁控制,各线程切换的很快
import time
import threading
def big_dog_sleep(wait):
print("big_dog_sleep")
time.sleep(wait)
print("big_dog_aweak")
def er_dog_sleep(wait):
print("er_dog_sleep")
time.sleep(wait)
print("er_dog_sweak")
# big_dog()
# er_dog()
t = threading.Thread(target=big_dog_sleep, args=(5,))
t.start()
t = threading.Thread(target=er_dog_sleep, args=(2,))
t.start()
#===============2、多进程
#多进程调用要在main的函数入口里
import time
import multiprocessing
def big_dog_sleep(wait):
print("big_dog_sleep")
time.sleep(wait)
print("big_dog_aweak")
def er_dog_sleep(wait):
print("er_dog_sleep")
time.sleep(wait)
print("er_dog_sweak")
# big_dog()
# er_dog()
if __name__ == '__main__':
p = multiprocessing.Process(target=big_dog_sleep, args=(3,))
p.start()
p = multiprocessing.Process(target=er_dog_sleep, args=(5,))
p.start()