Python进程间通信用法实例
作者:MaxOmnis 时间:2023-02-13 02:53:18
本文实例讲述了Python进程间通信用法。分享给大家供大家参考。具体如下:
#!/usr/bin/env python
# -*- coding=utf-8 -*-
import multiprocessing
def counsumer(input_q):
while True:
item = input_q.get()
#处理项目
print item #此处替换为有用的工作
#发出信号通知任务完成
input_q.task_done()
def producer(sequence,output_q):
for item in sequence:
#将项目放入队列
output_q.put(item)
#建立进程
if __name__ == '__main__':
q = multiprocessing.JoinableQueue()#创建可连接的共享进程队列
cons_q = multiprocessing.Process(target=counsumer,args=(q,))
cons_q.daemon = True
cons_q.start()
sequence = [1,2,3,4]
producer(sequence,q)
q.join()
print 'success'
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,进程,通信
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
常用SQL语句查询分享
2024-01-12 16:13:11
Python使用SQLite和Excel操作进行数据分析
2023-11-27 22:32:28
go语言Pflag Viper Cobra 核心功能使用介绍
2024-04-25 15:26:28
前端框架之封装Vue第三方组件三个技巧
2023-07-02 16:37:03
![](https://img.aspxhome.com/file/2023/9/139739_0s.jpg)
SecureCRT的下载、安装详细过程
2022-02-24 23:10:32
![](https://img.aspxhome.com/file/2023/0/131770_0s.png)
python中xrange和range的区别
2023-03-14 05:54:35
PHP json格式和js json格式 js跨域调用实现代码
2023-11-22 05:20:18
python获取网络图片方法及整理过程详解
2022-10-21 19:33:20
Sql Server基本函数
2008-08-20 18:28:00
PHP引用(&)各种使用方法实例详解
2023-11-01 18:12:43
Python Request类源码实现方法及原理解析
2021-03-23 02:23:50
![](https://img.aspxhome.com/file/2023/9/112569_0s.jpg)
如何用python处理excel表格
2021-04-21 04:06:55
Echarts基本入门之柱状图、折线图通用配置
2024-04-28 09:37:10
![](https://img.aspxhome.com/file/2023/6/132856_0s.png)
PHP使用观察者模式处理异常信息的方法详解
2023-10-19 15:53:30
Eclipse+Java+Swing+Mysql实现电影购票系统(详细代码)
2024-01-16 08:09:21
![](https://img.aspxhome.com/file/2023/5/94375_0s.png)
用Python实现QQ游戏大家来找茬辅助工具
2021-09-10 16:28:44
![](https://img.aspxhome.com/file/2023/5/70705_0s.png)
通过XSL转换XML文件步骤
2008-01-27 16:03:00
小谈用户身体语言的阅读经验
2009-10-19 20:52:00
![](https://img.aspxhome.com/file/UploadPic/200910/19/bodylanguage-banner-72s.jpg)
浅谈javascript获取元素transform参数
2024-04-16 10:32:39
![](https://img.aspxhome.com/file/2023/5/136655_0s.png)
记一次python 内存泄漏问题及解决过程
2021-06-18 17:28:14
![](https://img.aspxhome.com/file/2023/1/110061_0s.jpg)