Unverified Commit 191748e0 authored by richardhuo-nv's avatar richardhuo-nv Committed by GitHub
Browse files

feat: automatically reserve port for assigning port number to endpoint and pubsub (#946)

parent 4faa026e
...@@ -32,7 +32,7 @@ from circus.arbiter import Arbiter as _Arbiter ...@@ -32,7 +32,7 @@ from circus.arbiter import Arbiter as _Arbiter
from circus.sockets import CircusSocket from circus.sockets import CircusSocket
from circus.watcher import Watcher from circus.watcher import Watcher
from .utils import ServiceProtocol from .utils import ServiceProtocol, reserve_free_port
class Arbiter(_Arbiter): class Arbiter(_Arbiter):
...@@ -99,11 +99,20 @@ def create_circus_watcher( ...@@ -99,11 +99,20 @@ def create_circus_watcher(
) )
def get_env_or_reserved_port(env_var):
port_env = os.environ.get(env_var)
if port_env:
return int(port_env)
else:
with reserve_free_port() as port:
return port
def create_arbiter( def create_arbiter(
watchers: list[Watcher], *, threaded: bool = False, **kwargs: Any watchers: list[Watcher], *, threaded: bool = False, **kwargs: Any
) -> Arbiter: ) -> Arbiter:
endpoint_port = int(os.environ.get("DYN_CIRCUS_ENDPOINT_PORT", "41234")) endpoint_port = get_env_or_reserved_port("DYN_CIRCUS_ENDPOINT_PORT")
pubsub_port = int(os.environ.get("DYN_CIRCUS_PUBSUB_PORT", "52345")) pubsub_port = get_env_or_reserved_port("DYN_CIRCUS_PUBSUB_PORT")
return Arbiter( return Arbiter(
watchers, watchers,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment