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

Function _start_stream_proxy

api_utils/app.py:99–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

97
98
99async def _start_stream_proxy():
100 stream_port_env = get_environment_variable("STREAM_PORT")
101 if stream_port_env != "0":
102 port = int(stream_port_env or 3120)
103 stream_proxy_server_env = (
104 get_environment_variable("UNIFIED_PROXY_CONFIG")
105 or get_environment_variable("HTTPS_PROXY")
106 or get_environment_variable("HTTP_PROXY")
107 )
108 state.logger.info(
109 f"Starting STREAM proxy on port {port} with upstream proxy: {stream_proxy_server_env}"
110 )
111 state.STREAM_QUEUE = multiprocessing.Queue()
112 state.STREAM_PROCESS = multiprocessing.Process(
113 target=stream.start,
114 args=(state.STREAM_QUEUE, port, stream_proxy_server_env),
115 )
116 state.STREAM_PROCESS.start()
117 state.logger.info("STREAM proxy process started. Waiting for 'READY' signal...")
118
119 try:
120 ready_signal = await asyncio.to_thread(state.STREAM_QUEUE.get, timeout=15)
121 if ready_signal == "READY":
122 state.logger.info(
123 "[SUCCESS] Received 'READY' signal from STREAM proxy."
124 )
125 else:
126 state.logger.warning(
127 f"Received unexpected signal from proxy: {ready_signal}"
128 )
129 except queue.Empty:
130 state.logger.error(
131 "[ERROR] Timed out waiting for STREAM proxy to become ready. Startup will likely fail."
132 )
133 raise RuntimeError("STREAM proxy failed to start in time.")
134
135
136async def _initialize_browser_and_page():

Calls 5

get_environment_variableFunction · 0.90
infoMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
startMethod · 0.45