学习python 多进程和多线程

'''
学习多进程和多线程
'''
import multiprocessing
    
def deadLoop():
    while True:
     pass


if __name__ == '__main__':#多进程必须写这一行
    p1 = multiprocessing.Process(target=deadLoop)
    p1.start()

    deadLoop()
'''
测试发现多进程能让cpu到百分之60,
'''
import threading
    
def test():
    while True:
    pass
    
t1 = threading.Thread(target=test)
t1.start()
'''
多线程只能到30
'''
while True:
    pass
'''
单线程死循环也是30
'''
View Code

猜你喜欢

转载自www.cnblogs.com/zhangbo2008/p/9247333.html