-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathasync_example_get.py
More file actions
39 lines (33 loc) · 1.17 KB
/
async_example_get.py
File metadata and controls
39 lines (33 loc) · 1.17 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
import json
from eas_prediction import QueueClient
if __name__ == '__main__':
# 创建输出队列对象,⽤于订阅读取输出结果数据。
sink_queue = QueueClient(
'http://xxx.cn-hangzhou.pai-eas.aliyuncs.com',
'service_name/sink')
sink_queue.set_token(
'xxx')
sink_queue.init()
# 从输出队列中watch数据,窗⼝为1。
i = 0
watcher = sink_queue.watch(0, 1, auto_commit=False)
for x in watcher.run():
data = x.data.decode('utf-8')
data = json.loads(data)
print(data.keys())
if data['success']:
print(data['image_url'])
print(data['oss_url'])
print(data['task_id'])
print(data['use_blade'])
print(data['seed'])
print(data['is_nsfw'])
else:
print(data['error_msg'])
# 每次收到⼀个请求数据后处理完成后⼿动commit。
sink_queue.commit(x.index)
i += 1
if i == 10:
break
# 关闭已经打开的watcher对象,每个客户端实例只允许存在⼀个watcher对象,若watcher对象不关闭,再运⾏时会报错。
watcher.close()