MCPcopy Create free account
hub / github.com/vercel/vercel / _invoke_lambda

Function _invoke_lambda

python/vercel-runtime/tests/test_runtime.py:133–199  ·  view source on GitHub ↗

Run vc_init.py in legacy mode and call vc_handler. Uses an extra pipe (fd 3) so vc_init.py's own print() calls don't pollute the JSON result.

(
    *,
    entrypoint_abs: pathlib.Path,
    entrypoint_rel: str,
    module_name: str,
    event: dict[str, Any],
    variable_name: str = "app",
)

Source from the content-addressed store, hash-verified

131
132
133async def _invoke_lambda(
134 *,
135 entrypoint_abs: pathlib.Path,
136 entrypoint_rel: str,
137 module_name: str,
138 event: dict[str, Any],
139 variable_name: str = "app",
140) -> dict[str, Any]:
141 """Run vc_init.py in legacy mode and call vc_handler.
142
143 Uses an extra pipe (fd 3) so vc_init.py's own print()
144 calls don't pollute the JSON result.
145 """
146 env = {
147 **_base_env(),
148 "__VC_HANDLER_ENTRYPOINT": entrypoint_rel,
149 "__VC_HANDLER_ENTRYPOINT_ABS": str(entrypoint_abs),
150 "__VC_HANDLER_MODULE_NAME": module_name,
151 "__VC_HANDLER_VARIABLE_NAME": variable_name,
152 }
153 env.pop("VERCEL_IPC_PATH", None)
154
155 result_r, result_w = os.pipe()
156 env["_RESULT_FD"] = str(result_w)
157
158 cmd = [sys.executable]
159 if _coverage_active():
160 cmd.append(str(_COV_WRAPPER))
161 cmd.extend([str(_LAMBDA_INVOKER), str(_VC_INIT)])
162
163 proc = await asyncio.create_subprocess_exec(
164 *cmd,
165 env=env,
166 stdin=asyncio.subprocess.PIPE,
167 stdout=asyncio.subprocess.PIPE,
168 stderr=asyncio.subprocess.PIPE,
169 pass_fds=(result_w,),
170 )
171 os.close(result_w)
172
173 try:
174 assert proc.stdin is not None
175 proc.stdin.write(json.dumps(event).encode())
176 proc.stdin.close()
177
178 loop = asyncio.get_running_loop()
179 result_data, _ = await asyncio.wait_for(
180 asyncio.gather(
181 loop.run_in_executor(
182 None,
183 lambda: os.read(result_r, 1_000_000),
184 ),
185 proc.wait(),
186 ),
187 timeout=10.0,
188 )
189 finally:
190 os.close(result_r)

Calls 10

_base_envFunction · 0.85
_coverage_activeFunction · 0.85
appendMethod · 0.80
decodeMethod · 0.80
popMethod · 0.45
extendMethod · 0.45
closeMethod · 0.45
writeMethod · 0.45
encodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected