實現(xiàn)過程
1.建立對象Queue
2.將隊列注冊到網(wǎng)絡
3.實例化對象綁定端口和authkey
4.啟動示例
5.通過網(wǎng)絡訪問Queue
6.創(chuàng)建任務上傳網(wǎng)絡Queue
Demo
# -*- coding: utf-8 -*-
from multiprocessing.managers import BaseManager
import time, Queue
#1
task_queue = Queue.Queue()
result_queue = Queue.Queue()
def get_task():
return task_queue
def get_result():
return result_queue
class Quequemanager(BaseManager):
pass
def run():
#2
Quequemanager.register('get_task_queue', callable=get_task)
Quequemanager.register('get_result_queue', callable=get_result)
#3
manager = Quequemanager(address=('127.0.0.1', 8001), authkey='qiye')
#4
manager.start()
try:
# 5
task = manager.get_task_queue()
result = manager.get_result_queue()
#創(chuàng)建任務
for url in ["ImageUrl_"+str(i) for i in range(1,10)]:
task.put(url)
print "put task %s ..." %url
print "try get result ..."
for i in range(10):
print "result is %s " %result.get(timeout=10)
print 'end'
except:
pass
finally:
manager.shutdown
if __name__ == '__main__':
run()