-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
70 lines (62 loc) · 1.49 KB
/
server.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from network import Server
_server = None
def _is_allocated():
try:
_server
print('allocated')
return True
except Exception as e:
print('not allocated', e)
return False
def _is_init():
v = False
if _is_allocated():
v = _server is not None
if v:
print('initialized')
else:
print('not initialized')
return v
def is_running():
v = False
if _is_init():
v = _server.isrunning()
if v:
print('running')
else:
print('not running')
else:
print('dont know')
# there is no instance initialized locally. Which means I cannot test wheter the server is running. it might be running, or it might not. Once we initiate the object we also automatically start is, so I'm not doing this here automatically
return None
return v
def _init():
print('initializing')
global _server
_server = Server()
def stop():
global _server
if not _is_init():
_init()
print('stopping')
_server.deinit()
else:
if is_running():
print('stopping')
_server.deinit()
else:
print('not running')
def start():
global _server
if not _is_init():
print('starting')
_init()
else:
if not is_running():
print('starting')
_server.init()
def restart():
global _server
print('restart')
stop()
start()