-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
30 lines (27 loc) · 1.02 KB
/
run.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
from __future__ import print_function
import librarian
from config import DefaultAlexandriaConfig as cfg
import os
import socket
import time
import traceback
if __name__ == "__main__":
exp_backoff = 0
print("Welcome to Alexandria. Starting up...")
while True:
try:
librarian.init_blueprints()
librarian.init_db()
librarian.app.run(host=cfg.APP_HOST, port=cfg.APP_PORT, debug=cfg.DEVEL)
# We need to catch socket.error too since it seems that Werkzeug (used
# Flask's _development_ environment) uses socket.py and somewhere there
# they already catch KeyboardInterrupt. Not doing this leads to a
# situation where you need to CTRL + C twice in order to quit the
# development server.
except (KeyboardInterrupt, SystemExit, socket.error):
raise
except Exception as e:
traceback.print_exc()
print("Can't start app, retrying...")
exp_backoff += 1
time.sleep(3 ** exp_backoff)