-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp_client.py
33 lines (27 loc) · 925 Bytes
/
app_client.py
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
import argparse
import threading
from rpc.client import Client
def func(client, lock):
a = client.sum(1.0, 2.0)
b = client.upper("abc")
c = client.lower("ABC")
with lock:
tid = threading.currentThread().ident
print("In thread pid:", tid)
print("client.sum(1.0, 2.0) = ", a)
print("client.upper('abc') = ", b)
print("client.lower('ABC') = ", c)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str, default="127.0.0.1", help="IP address.")
parser.add_argument("--port", type=int, default=6006, help="Listening port.")
args = parser.parse_args()
client = Client(args.ip, args.port)
client.set_timeout(5)
ts = []
lock = threading.Lock()
for i in range(12):
t = threading.Thread(target=func, args=(client, lock))
t.daemon = False
ts.append(t)
t.start()