2 Commits

Author SHA1 Message Date
Joakim Persson f5244ee88b Fler utskrifter för felsökningsändamål 2024-07-19 10:40:40 +02:00
Joakim Persson a18bfca9f8 Lade till några utskrifter för felsökning 2024-07-19 10:39:38 +02:00
2 changed files with 11 additions and 8 deletions
+3 -1
View File
@@ -82,8 +82,10 @@ def get_response(user_query):
def run_flask(fport=5005): def run_flask(fport=5005):
# Flask endpoint for user interaction # Flask endpoint for user interaction
app.run(str(fport), debug=True) print(f"Entering run_flask()")
app.run(port = str(str(fport)), debug=False)
# app.run(port=5000, debug=True, use_reloader=False) # app.run(port=5000, debug=True, use_reloader=False)
print(f"Exiting run_flask()")
if __name__ == '__main__': if __name__ == '__main__':
+7 -6
View File
@@ -2,6 +2,7 @@
import subprocess import subprocess
import os import os
import yaml import yaml
import json
from backend import run_flask from backend import run_flask
import socket import socket
import urllib.parse import urllib.parse
@@ -40,12 +41,12 @@ def start_frontend(config):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try: try:
s.bind((hostname, port)) s.bind((hostname, port))
print("No server is running on this host and port.") print(f"No server is running on {parsed_url.netloc} —- starting up one.")
# Start frontend (web server) as a separate process # Start frontend (web server) as a separate process
subprocess.Popen(["python", "-m", "http.server", str(port)]) subprocess.Popen(["python", "-m", "http.server", str(port)])
except socket.error as e: except socket.error as e:
if e.errno == 48: if e.errno == 48:
print("Another server is already running on this host and port. Assumes it is a web server, will continue.") print(f"A server is already running on {parsed_url.netloc} -— will use this.")
else: else:
raise # Unexpected error, re-raise it so we can see the traceback raise # Unexpected error, re-raise it so we can see the traceback
except Exception as e: except Exception as e:
@@ -56,16 +57,16 @@ def start_backend(config):
parsed_url = urllib.parse.urlparse(config['backend']['url']) parsed_url = urllib.parse.urlparse(config['backend']['url'])
# hostname = parsed_url.netloc.split(':')[0] # Split by ':' and take the first part, i.e., 'localhost', IP, or domain name # hostname = parsed_url.netloc.split(':')[0] # Split by ':' and take the first part, i.e., 'localhost', IP, or domain name
port = parsed_url.port # This is the server port port = parsed_url.port # This is the server port
print(f"{port}") # print(f"{port}")
try: try:
run_flask(port = port) run_flask(fport = port)
except Exception as e: except Exception as e:
print(f"Failed to start backend: {e}") print(f"Failed to start backend: {e}")
if __name__ == '__main__': if __name__ == '__main__':
conf = configure() # Read config from file and set up config dict conf = configure() # Read config from file and set up config dict
print(conf) print(json.dumps(conf, indent=4))
start_frontend(config=conf) # No need for this as the backend starts a web server on its own. start_frontend(config=conf)
start_backend(config=conf) start_backend(config=conf)