Skip to content

Commit

Permalink
Use waitress WSGI server
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanzwicknagl committed Jul 9, 2024
1 parent 52fed23 commit c2bda2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions backend/src/viasp/server/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT):
else:
backend_url = f"{DEFAULT_BACKEND_PROTOCOL}://{host}:{port}"

command = ["viasp_server", "--host", host, "--port", str(port)]

env = os.getenv("ENV", "production")
if env == "production":
command = ["waitress-serve", "--host", host, "--port", str(port), "--call", "viasp.server.factory:create_app"]
else:
command = ["viasp_server", "--host", host, "--port", str(port)]
# if 'ipykernel_launcher.py' in sys.argv[0]:
# display_refresh_button()

print(f"Starting backend at {backend_url}")
log = open('viasp.log', 'w', encoding="utf-8")
viasp_backend = Popen(command, stdout=log, stderr=log)

color_palette = json.load(
open(COLOR_PALETTE_PATH, "r"))
color_palette = json.load(open(COLOR_PALETTE_PATH, "r"))
app = Dash(__name__)
app.layout = viasp_dash.ViaspDash(id="myID",
backendURL=backend_url,
Expand All @@ -79,19 +81,18 @@ def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT):
wait_exponential_max=10000,
)
def wait_for_backend():
try:
try:
assert clingoApiClient.backend_is_running(backend_url)
except Exception as e:
raise Exception("Backend did not start in time.") from e

try:
wait_for_backend()
except Exception as final_error:
print(f"Error: {final_error}")
viasp_backend.terminate()
raise final_error


def terminate_process(process):
""" kill the backend on keyboard interruptions"""
print("\nKilling Backend")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ igraph>=0.8
numpy
clingraph
retrying
waitress

0 comments on commit c2bda2f

Please sign in to comment.