Skip to content

Commit 0d2875d

Browse files
committed
Handle running tracker before benchmark start
1 parent ea82f8e commit 0d2875d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

bench/orchestrator_server.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ def wait_for_udp(host: str, port: int, timeout: float) -> bool:
105105
return False
106106

107107

108+
def tracker_alive(http_host: str, http_port: int, udp_host: str, udp_port: int) -> bool:
109+
if http_port > 0 and wait_for_http(http_host, http_port, 1.0):
110+
return True
111+
if udp_port > 0 and wait_for_udp(udp_host, udp_port, 1.0):
112+
return True
113+
return False
114+
115+
108116
def default_cache_dir() -> Optional[Path]:
109117
xdg = os.environ.get("XDG_CACHE_HOME")
110118
if xdg:
@@ -196,7 +204,17 @@ def main() -> int:
196204
if http_routines is not None:
197205
env["TRAKX_HTTP_ROUTINES"] = str(http_routines)
198206

199-
_ = run_cmd([args.trakx_bin, "--config", args.config, "stop"], env=env)
207+
if tracker_alive(args.http_host, args.http_port, args.udp_host, args.udp_port):
208+
_ = run_cmd([args.trakx_bin, "--config", args.config, "stop"], env=env)
209+
stop_deadline = time.time() + args.ready_timeout
210+
while time.time() < stop_deadline:
211+
if not tracker_alive(args.http_host, args.http_port, args.udp_host, args.udp_port):
212+
break
213+
time.sleep(0.2)
214+
if tracker_alive(args.http_host, args.http_port, args.udp_host, args.udp_port):
215+
send_msg(conn_file, {"type": "ERROR", "message": "tracker already running; stop it and retry"})
216+
continue
217+
200218
clear_cache(cache_dir)
201219

202220
start = run_cmd([args.trakx_bin, "--config", args.config, "start"], env=env)

0 commit comments

Comments
 (0)