python process,queue
2015-07-07 10:15
661 查看
#-*- coding:utf-8 -*- from multiprocessing import Process,Queue import os,time,random def write(q): for value in ['A','B','C']: print 'Put %s to queue...and Ospid is %s'%(value,os.getpid()) q.put(value) time.sleep(random.random()) def read(q): while True: value = q.get(True) print 'Get %s from queue.and Ospid is %s'%(value,os.getpid()) if __name__ == '__main__': q=Queue() pw = Process(target=write,args=(q,)) pr = Process(target=read,args=(q,)) pw.start() pr.start() pw.join() pr.terminate() print 'Main processes is 'and os.getpid()
结果:
Put A to queue...and Ospid is 7556
Get A from queue.and Ospid is 7324
Put B to queue...and Ospid is 7556
Get B from queue.and Ospid is 7324
Put C to queue...and Ospid is 7556
Get C from queue.and Ospid is 7324
7380
相关文章推荐
- python 进程池Pool
- 在Win7中使用Python的MySQLdb模块
- 在Win7中使用Python的MySQLdb模块
- Python学习之文件读写
- Python笔记:性能优化指南
- Python3爬虫爬取某网站美女图片
- yum 遇到 python运行问题
- Python自学笔记之函数式编程4——sorted
- Python 的一些高级特性
- boost.python编译及示例
- python unicode&str 转化
- Python中的urllib模块使用详解
- Python的多态性实例分析
- python生成IP段的方法
- python妹子图简单爬虫实例
- Python实现爬取逐浪小说的方法
- Python变量作用范围实例分析
- Python实现合并字典的方法
- python类和继承用法实例
- Python可变参数函数用法实例