forked from s-brez/trading-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.py
35 lines (27 loc) · 942 Bytes
/
server_test.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
from urllib3.exceptions import NewConnectionError, MaxRetryError, TimeoutError
from requests.exceptions import ConnectionError
from time import sleep
from os import system
import subprocess
import platform
import socket
from server import Server
RETRY_TIME = 60
host_os = platform.system()
server = Server()
try:
server.run()
except (ConnectionError, NewConnectionError, MaxRetryError, TimeoutError):
# kill all python proccesses, wait and restart
if host_os == "Windows":
system('cmd /k "taskkill /IM python.exe /F"')
print("Server restart in 1 minute.")
sleep(RETRY_TIME)
system('cmd /k "python server_test.py"')
elif host_os == "Linux":
subprocess.check_output(["pkill" "-9" "python"])
print("Server restart in 1 minute.")
sleep(RETRY_TIME)
subprocess.check_output(["python", "server_test.py"])
else:
print("Unknown kernel. Terminating.")