#_*_coding:utf-8_*_
from  multiprocessing import Process,Queue
import os,time
def f(q,n):
    q.put([n,'hello'])
if __name__ == '__main__':
    #此queue不是直接导入的import Queue,这个是multiprocessing重新封装的
    q=Queue()
    #循环6个进程
    for i in range(5):
           p=Process(target=f,args=(q,i))
           p.start()
    #等待子进程完毕后在继续执行
    p.join()
    for i in range(q.qsize()):
         print(q.get())

输出

[2, 'hello']
[1, 'hello']
[0, 'hello']
[3, 'hello']
[4, 'hello']

 

相关文章:

  • 2021-11-19
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2021-08-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2021-09-26
  • 2022-12-23
  • 2021-06-18
  • 2021-06-10
相关资源
相似解决方案