zoukankan      html  css  js  c++  java
  • python中的BaseManager通信(二)文件二分

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

     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 

  • 相关阅读:
    C++结构体中sizeof
    sizeof()的用法
    XStream和Json
    省市联动
    ajax
    配置文件的读取
    JSP标签库
    字符串函数参数传入传出(去空格)
    字符串函数参数传入传出(字符串反转)
    opendir,readdir,closedir
  • 原文地址:https://www.cnblogs.com/liunnis/p/4614950.html
Copyright © 2011-2022 走看看