Vision / launcher.py
kishankrish19's picture
Deploy MoM application
5e16fc6
Raw History Blame Contribute Delete
1.32 kB
"""Windows double-click entry point with browser opening and persistent server."""
import threading
import urllib.request
import webbrowser
from app import create_app
from waitress import serve
URL='http://127.0.0.1:5000'
def open_when_ready():
import time
for _ in range(50):
try:
with urllib.request.urlopen(URL+'/login',timeout=1) as response:
if response.status==200:
webbrowser.open(URL)
return
except OSError:
time.sleep(.2)
if __name__=='__main__':
try:
with urllib.request.urlopen(URL+'/login',timeout=1) as response:
existing=response.read().decode('utf-8')
if 'Sign in · MOM' in existing:
webbrowser.open(URL)
print('The MOM app is already running. Opened it in your browser.')
raise SystemExit(0)
except OSError:
pass
app=create_app()
print('MOM is running at '+URL+'\nKeep this window open while using the app. Press Ctrl+C to stop.',flush=True)
threading.Thread(target=open_when_ready,daemon=True).start()
try:
serve(app,host='127.0.0.1',port=5000,threads=4)
except OSError as error:
print('Could not start the app. Port 5000 may be in use: '+str(error))
raise SystemExit(1)