-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcloud_api.py
50 lines (41 loc) · 1.51 KB
/
cloud_api.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import torch
import sys,getopt
import warnings
warnings.filterwarnings("ignore")
from net.monitor_server import MonitorServer
from server_func import start_server
from net import net_utils
"""
云端设备api 用于接收中间数据,并在云端执行剩余的DNN部分,将结果保存在excel表格中
server 启动指令 python cloud_api.py -i 127.0.0.1 -p 9999 -d cpu
"-i", "--ip" 服务端 ip地址
"-p", "--port" 服务端 开放端口
"-d", "--device" 是否开启服务端GPU计算 cpu or cuda
"""
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], "i:p:d:", ["ip=","port=","device"])
except getopt.GetoptError:
print('input argv error')
sys.exit(2)
# 处理 options中以元组的方式存在(opt,arg)
ip,port = "127.0.0.1",8090
device = "cpu"
for opt, arg in opts:
if opt in ("-i", "--ip"):
ip = arg
elif opt in ("-p", "--port"):
port = int(arg)
elif opt in ("-d", "--device"):
device = arg
if device == "cuda" and torch.cuda.is_available() == False:
raise RuntimeError("本机器上不可以使用cuda")
while True:
# 开启服务端进行监听
socket_server = net_utils.get_socket_server(ip, port)
# 开启:带宽监测服务端
monitor_ser = MonitorServer(ip=ip)
monitor_ser.start()
monitor_ser.join()
start_server(socket_server,device)
monitor_ser.terminate()