MCPcopy Create free account
hub / github.com/1jehuang/jcode / start_server

Function start_server

scripts/benchmark_discovery.py:545–589  ·  view source on GitHub ↗
(args: argparse.Namespace, socket_path: Path)

Source from the content-addressed store, hash-verified

543
544
545def start_server(args: argparse.Namespace, socket_path: Path) -> subprocess.Popen[str]:
546 socket_path.unlink(missing_ok=True)
547 command = [
548 args.jcode,
549 "--socket",
550 str(socket_path),
551 "--no-selfdev",
552 "--no-update",
553 ]
554 if args.provider:
555 command += ["--provider", args.provider]
556 command += ["serve", "--server-name", f"discovery-benchmark-{os.getpid()}"]
557 environment = benchmark_environment(socket_path)
558 log_path = socket_path.parent / "server.log"
559 log = log_path.open("w", encoding="utf-8")
560 process = subprocess.Popen(
561 command,
562 stdout=log,
563 stderr=subprocess.STDOUT,
564 text=True,
565 env=environment,
566 start_new_session=True,
567 )
568 log.close()
569 deadline = time.monotonic() + 20
570 while time.monotonic() < deadline:
571 try:
572 probe = subprocess.run(
573 [args.jcode, "--socket", str(socket_path), "debug", "server:info"],
574 capture_output=True,
575 text=True,
576 env=environment,
577 timeout=2,
578 )
579 if probe.returncode == 0:
580 return process
581 except subprocess.TimeoutExpired:
582 pass
583 if process.poll() not in (None, 0):
584 details = log_path.read_text(encoding="utf-8", errors="replace")[-4000:]
585 raise BenchmarkError(f"benchmark server exited early: {details}")
586 time.sleep(0.2)
587 terminate_process(process)
588 details = log_path.read_text(encoding="utf-8", errors="replace")[-4000:]
589 raise BenchmarkError(f"benchmark server did not become ready on {socket_path}: {details}")
590
591
592def stop_server(args: argparse.Namespace, socket_path: Path, process: subprocess.Popen[str]) -> None:

Callers 1

mainFunction · 0.85

Calls 7

benchmark_environmentFunction · 0.85
BenchmarkErrorClass · 0.85
terminate_processFunction · 0.85
openMethod · 0.45
closeMethod · 0.45
runMethod · 0.45
pollMethod · 0.45

Tested by

no test coverage detected