欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

python 分布式进程例子 queue

shiping1 的头像
#taskmanager2.py
from multiprocessing.managers import BaseManager
import Queue
queue = Queue.Queue()
class QueueManager(BaseManager): pass
QueueManager.register('get_queue', callable=lambda:queue)
m = QueueManager(address=('', 50000), authkey='abracadabra')
s = m.get_server()
s.serve_forever()



#taskworker2.py
from multiprocessing.managers import BaseManager
class QueueManager(BaseManager): pass
QueueManager.register('get_queue')
m = QueueManager(address=('127.0.0.1', 50000), authkey='abracadabra')
m.connect()
queue = m.get_queue()
queue.put('hello')

来自 https://docs.python.org/2/library/multiprocessing.html?highlight=basemanager#multiprocessing.manager...


#taskworker2-2.py
from multiprocessing.managers import BaseManager
class QueueManager(BaseManager): pass
QueueManager.register('get_queue')
m = QueueManager(address=('127.0.0.1', 50000), authkey='abracadabra')
m.connect()
queue = m.get_queue()
value = queue.get()
print value

普通分类: