码迷,mamicode.com
首页 > 编程语言 > 详细

python 进程队列

时间:2019-01-29 13:58:12      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:span   proc   封装   from   pytho   time   queue   color   style   

 

#_*_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]

 

python 进程队列

标签:span   proc   封装   from   pytho   time   queue   color   style   

原文地址:https://www.cnblogs.com/sea-stream/p/10333499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!