MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / _determine_launch_mode

Method _determine_launch_mode

launcher/runner.py:125–188  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

123 logger.info("Launcher main logic completed")
124
125 def _determine_launch_mode(self):
126 if self.args.debug:
127 self.final_launch_mode = "debug"
128 elif self.args.headless:
129 self.final_launch_mode = "headless"
130 elif self.args.virtual_display:
131 self.final_launch_mode = "virtual_headless"
132 if platform.system() != "Linux":
133 logger.warning(
134 "--virtual-display is designed for Linux. Behavior on other systems may be unpredictable."
135 )
136 else:
137 env_launch_mode = os.environ.get("LAUNCH_MODE", "").lower()
138 default_mode_from_env = None
139 default_interactive_choice = "1"
140
141 if env_launch_mode == "headless":
142 default_mode_from_env = "headless"
143 default_interactive_choice = "1"
144 elif env_launch_mode == "debug" or env_launch_mode == "normal":
145 default_mode_from_env = "debug"
146 default_interactive_choice = "2"
147 elif env_launch_mode in ("virtual_display", "virtual_headless"):
148 default_mode_from_env = "virtual_headless"
149 default_interactive_choice = (
150 "3" if platform.system() == "Linux" else "1"
151 )
152
153 if DIRECT_LAUNCH:
154 self.final_launch_mode = default_mode_from_env or "headless"
155 return
156
157 logger.info("--- Select Launch Mode (Not specified via CLI) ---")
158 if env_launch_mode and default_mode_from_env:
159 logger.info(
160 f" Default mode from .env: {env_launch_mode} -> {default_mode_from_env}"
161 )
162
163 prompt_options_text = "[1] Headless, [2] Debug"
164 valid_choices = {"1": "headless", "2": "debug"}
165
166 if platform.system() == "Linux":
167 prompt_options_text += ", [3] Headless (Virtual Display Xvfb)"
168 valid_choices["3"] = "virtual_headless"
169
170 default_mode_name = valid_choices.get(
171 default_interactive_choice, "headless"
172 )
173 user_mode_choice = (
174 input_with_timeout(
175 f" Enter launch mode ({prompt_options_text}; Default: {default_interactive_choice} {default_mode_name} mode, 15s timeout): ",
176 15,
177 )
178 or default_interactive_choice
179 )
180
181 if user_mode_choice in valid_choices:
182 self.final_launch_mode = valid_choices[user_mode_choice]

Callers 1

runMethod · 0.95

Calls 5

input_with_timeoutFunction · 0.90
warningMethod · 0.80
infoMethod · 0.80
debugMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected