Uh oh!
There was an error while loading. Please reload this page.
forked from SergioJune/python_test
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest36.py
More file actions
Latest commit
39 lines (32 loc) · 1.03 KB
/
Copy pathtest36.py
File metadata and controls
39 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'处理分布式进程发送的数据'
__author__='sergiojune'
frommultiprocessing.managersimportBaseManager
importtime, queue
classQueueManager(BaseManager):
pass
# 注册到网络上
QueueManager.register('post_task_queue') # 由于只是从网络上获取queue,所以不需要写callable方法
QueueManager.register('result_task_queue')
# 连接到网络
address='127.0.0.1'# 这个是网络地址
manager=QueueManager(address=(address, 500), authkey=b'abc') # 这些必须与发送的一致,要不会连不上
# 连接
manager.connect()
# 获取queue
post=manager.post_task_queue()
result=manager.result_task_queue()
# 处理数据
print('tyr get value')
forxinrange(10):
try:
v=post.get(timeout=10)
print('get value %d'%v)
r=v*v
print('put value %d to result'%r)
time.sleep(1)
result.put(r)
exceptqueue.Emptyase:
print('Queue is empty')
print('work exit')