-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy paththread_test.py
More file actions
executable file
·52 lines (40 loc) · 1.11 KB
/
thread_test.py
File metadata and controls
executable file
·52 lines (40 loc) · 1.11 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
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2020-09-03 00:56:04
# @Author : Kaiyan Zhang (minekaiyan@gmail.com)
# @Link : https://github.com/iseesaw
# @Version : 1.0.0
from threading import Thread
import requests
import random
import json
import time
API_URL = "http://127.0.0.1:8889/module/ext_faq_test"
NUM_REQUESTS = 500
SLEEP_COUNT = 0.1
def get_seqs():
"""获取用户输入样例
Returns:
List[str]
"""
seqs = []
with open('./hflqa/test_faq_resp.json', 'r', encoding='utf-8') as f:
data = json.load(f)
for _, post_resp in data.items():
seqs.extend(post_resp['post'])
random.shuffle(seqs)
return seqs
seqs = get_seqs()
def call_predict_endpoint(n):
payload = {"query": random.choice(seqs)}
r = requests.post(API_URL, files=payload).json()
if r["reply"]:
print("[INFO] thread {} OK".format(n))
else:
print("[INFO] thread {} FAILED".format(n))
for i in range(0, NUM_REQUESTS):
t = Thread(target=call_predict_endpoint, args=(i,))
t.daemon = True
t.start()
time.sleep(SLEEP_COUNT)
time.sleep(300)