Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move where the executor process port is defined #2649

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions backend/src/server_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import asyncio
import logging
import socket
import sys
from concurrent.futures import ThreadPoolExecutor
from dataclasses import asdict, dataclass
Expand All @@ -24,13 +23,6 @@
from server_process_helper import ExecutorServer


def find_free_port():
# return 8001
with socket.socket() as s:
s.bind(("", 0)) # Bind to a free port provided by the host.
return s.getsockname()[1] # Return the port number assigned.


class AppContext:
def __init__(self):
self.config: ServerConfig = None # type: ignore
Expand Down Expand Up @@ -59,8 +51,7 @@ def filter(self, record): # noqa: ANN001
)


port = find_free_port()
executor_server: ExecutorServer = ExecutorServer(port)
executor_server: ExecutorServer = ExecutorServer()

setup_task = None

Expand Down
13 changes: 10 additions & 3 deletions backend/src/server_process_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import os
import socket
import subprocess
import sys
import threading
Expand All @@ -13,6 +14,12 @@
from api import Package


def find_free_port():
with socket.socket() as s:
s.bind(("", 0)) # Bind to a free port provided by the host.
return s.getsockname()[1] # Return the port number assigned.


class ExecutorServerWorker:
def __init__(self, port: int, flags: list[str] | None = None):
self.process = None
Expand Down Expand Up @@ -56,13 +63,13 @@ def _read_output(self):


class ExecutorServer:
def __init__(self, port: int, flags: list[str] | None = None):
self.port = port
def __init__(self, flags: list[str] | None = None):
self.flags = flags

self.server_process = None

self.base_url = f"http://127.0.0.1:{port}"
self.port = find_free_port()
self.base_url = f"http://127.0.0.1:{self.port}"
self.session = None

self.backend_ready = False
Expand Down
Loading