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",
)
| 131 | |
| 132 | |
| 133 | async 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) |
no test coverage detected