-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
executable file
·47 lines (40 loc) · 1.07 KB
/
main.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
#!/usr/bin/env pypy3
from traceback import print_exc
import sys
import time
import importlib
def reset_modules():
pending = []
for module in sys.modules:
if module.startswith("pyeod"):
pending.append(module)
for mod in pending:
sys.modules.pop(mod)
# Do not run web server in production
if len(sys.argv) > 1:
run_web_server = False
else:
run_web_server = True
def main():
while True:
reset_modules()
proc = None
if run_web_server:
control = importlib.import_module("pyeod.control")
proc = control.run_webserver()
try:
bot = importlib.import_module("pyeod.bot")
should_continue = bot.run()
except Exception:
if proc is not None:
proc.terminate()
print_exc()
print("Restarting bot in 5 seconds")
time.sleep(5)
else:
if proc is not None:
proc.terminate()
if not should_continue:
break
if __name__ == "__main__":
main()