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

python中的BaseManager通信(二)文件二分

时间:2015-07-02 01:00:27      阅读:939      评论:0      收藏:0      [点我收藏+]

标签:

提供服务部分(运行时在接收端未打开前不能关闭)

 1 #mainsec.py
 2 from multiprocessing import Process, Queue
 3 from multiprocessing.managers import BaseManager
 4 class Worker(Process):
 5     def __init__(self, q):
 6         self.q = q
 7         super(Worker, self).__init__()
 8     def run(self):
 9         self.q.put(local hello)
10 if __name__ == __main__:
11     queue = Queue()
12     w = Worker(queue)
13     w.start()
14     class QueueManager(BaseManager): pass
15 
16     QueueManager.register(get_queue, callable=lambda: queue)
17     m = QueueManager(address=(127.0.0.1, 50000), authkey=abc)
18     s = m.get_server()
19     s.serve_forever()

接收方(接收):

1 #subthir.py
2 from multiprocessing.managers import BaseManager
3 class QueueManager(BaseManager): pass
4 QueueManager.register(get_queue)
5 m = QueueManager(address=(127.0.0.1, 50000), authkey=abc)
6 m.connect()
7 queue = m.get_queue()
8 print m.address
9 print queue.get()

结果:

 1 (127.0.0.1, 50000)

 2 local hello 

 

python中的BaseManager通信(二)文件二分

标签:

原文地址:http://www.cnblogs.com/liunnis/p/4614950.html

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