Skip to content

Commit

Permalink
chore: prevent multiple instances (#386)
Browse files Browse the repository at this point in the history
* chore: prevent multiple instances

* fix: linting

---------

Co-authored-by: Frederik Hvilshøj <[email protected]>
  • Loading branch information
Encord-davids and frederik-encord authored May 9, 2023
1 parent 244a6cc commit 41d02e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/encord_active/cli/utils/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from os import environ
from pathlib import Path

import rich
from streamlit.web import cli as stcli

from encord_active.app.app_config import app_config
Expand All @@ -29,7 +30,22 @@ def ensure_safe_project(path: Path):
ensure_prisma_db(project_file_structure.prisma_db)


def is_port_in_use(port: int) -> bool:
import socket

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(("localhost", port)) == 0


def launch_streamlit_app(target: Path):
if is_port_in_use(8501):
import typer

rich.print("[red]Port already in use...")
raise typer.Exit()
else:
rich.print("[yellow]Bear with us, this might take a short while...")

if did_schema_change():
generate_prisma_client()
ensure_safe_project(target)
Expand Down
2 changes: 1 addition & 1 deletion src/encord_active/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

app = FastAPI()

origins = ["http://localhost:5173", "http://localhost:8501", settings.ALLOWED_ORIGIN]
origins = [settings.ALLOWED_ORIGIN]

app.add_middleware(
CORSMiddleware,
Expand Down

0 comments on commit 41d02e0

Please sign in to comment.