进程

Python中的多线程无法利用多核优势 , 所以如果我们想要充分地使用多核CPU的资源 , 那么就只能靠多进程了

multiprocessing模块中提供了Process , Queue , Pipe , Lock , RLock , Event , Condition等组件 , 与threading模块有很多相似之处

1.创建进程

from multiprocessing import Process
import time

def func(name):
    time.sleep(2)
    print('hello',name)

if __name__ == '__main__':
    p= Process(target=func,args=('derek',))
    p.start()
    # p.join()
    print('end...')
View Code

相关文章:

  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-03
  • 2021-09-18
猜你喜欢
  • 2022-12-23
  • 2021-09-08
  • 2021-08-26
  • 2022-12-23
  • 2021-12-28
  • 2021-05-18
  • 2021-10-05
相关资源
相似解决方案