demon16.1-16.2
来源:互联网 发布:电脑软件 著作权 专利 编辑:程序博客网 时间:2024/06/01 08:35
#!/usr/bin/env python# -*- coding:utf-8 -*-'''多进程的消息队列'''from multiprocessing import Queueimport multiprocessingdef write(q): for i in ['a','b','c','d']: q.put(i) print('put {0} to queue'.format(i))def read(q): while 1: result = q.get() #print(result) print('get {0} from queue'.format(result))def main(): q = Queue() pw = multiprocessing.Process(target=write,args=(q,)) pr = multiprocessing.Process(target=read,args=(q,)) pw.start() pr.start() pw.join() pw.terminate() #没有消息的时候,结束,不在写入if __name__ =="__main__": main()
#!/usr/bin/env python# -*- coding:utf-8 -*-'''消息队列pie'''from multiprocessing import Queue,Pipe,Processimport timedef proc1(pipe): for i in xrange(1,10): pipe.send(i) print('send {0} to pipe'.format(i))def proc2(pipe): n = 9 while n>0: result = pipe.recv() print('recv {0} from pipe'.format(result))def main(): pipe = Pipe(duplex=False) ##F为逆向传输,T为双工型,两边都可以传输 p1 = Process(target=proc1,args=(pipe[1],)) p2 = Process(target=proc2,args=(pipe[0],)) p1.start() p2.start() p1.join() p2.join() pipe[0].close() ##关闭 pipe[1].close()if __name__ == '__main__': main()
阅读全文
0 0
- demon16.1-16.2
- 16.2.1
- 算法导论16.2-1
- 16.2.1 使用 switch 函数
- 16.2
- 16.2
- 16.2
- 16.2
- 16.2.1 进行正则表达式匹配
- 16.2.1 D-Bus的基本概念
- 16.2.1 如何获取Apache软件
- 第十六章 16.2.1节练习
- 16.2 最简单界面程序(1)
- 精通COBOL--16.2.1 CICS程序编译流程
- 算法导论16.2-2 0-1背包问题
- 16.2-5
- 16.2 vector
- 16.2.2
- add two num
- Spring框架开发包下载地址
- EM算法与Baum-Welch算法
- RobocupRescue & Java(2)
- Python:数据库操作模块SQLAlchemy
- demon16.1-16.2
- 关于ext4 buddy bitmap构建分析
- redis-JedisPoolConfig配置
- 第九周项目一__二叉树算法库
- matlab中,GUI窗口位置和大小问题
- CodeForce896 B. Ithea Plays With Chtholly
- 475. Heaters
- javascript连接SQL Server 2014进行增删改查(适用于IE浏览器)
- 一文览尽2017年下半年机器人行业融资大事件