MCPcopy
hub / github.com/allenai/open-instruct / start

Method start

open_instruct/code_utils/test_api.py:33–66  ·  view source on GitHub ↗

Start the server if it's not already running.

(self)

Source from the content-addressed store, hash-verified

31 return False
32
33 def start(self):
34 """Start the server if it's not already running."""
35 if self.is_running():
36 logger.info("Server already running, using existing instance")
37 return True
38
39 logger.info("Starting API server...")
40 self.process = subprocess.Popen(
41 [
42 "uv",
43 "run",
44 "uvicorn",
45 "open_instruct.code_utils.api:app",
46 "--host",
47 self.host,
48 "--port",
49 str(self.port),
50 ],
51 stdout=subprocess.PIPE,
52 stderr=subprocess.PIPE,
53 )
54
55 # Wait for server to start
56 for _ in range(self.startup_timeout):
57 if self.is_running():
58 logger.info("Server started successfully")
59 return True
60 time.sleep(1)
61
62 # Server failed to start
63 if self.process:
64 self.process.terminate()
65 self.process = None
66 raise RuntimeError(f"Failed to start server within {self.startup_timeout} seconds")
67
68 def stop(self):
69 """Stop the server if we started it."""

Callers 4

__enter__Method · 0.95
__enter__Method · 0.45

Calls 2

is_runningMethod · 0.95
sleepMethod · 0.80

Tested by

no test coverage detected