| 401 | return result |
| 402 | |
| 403 | def spawn_debuggee(self, args, cwd=None, exe=sys.executable, setup=None): |
| 404 | assert self.debuggee is None |
| 405 | assert not len(self.captured_output - {"stdout", "stderr"}) |
| 406 | |
| 407 | args = self._make_python_cmdline(exe, *args) |
| 408 | cwd = cwd.strpath if isinstance(cwd, py.path.local) else cwd |
| 409 | |
| 410 | env = self._make_env(self.spawn_debuggee.env, codecov=False) |
| 411 | self.adapter_endpoints = self.tmpdir / "adapter_endpoints" |
| 412 | env["DEBUGPY_ADAPTER_ENDPOINTS"] = self.adapter_endpoints.strpath |
| 413 | if setup is not None: |
| 414 | env["DEBUGPY_TEST_DEBUGGEE_SETUP"] = setup |
| 415 | |
| 416 | log.info( |
| 417 | "Spawning {0}:\n\n" |
| 418 | "Current directory: {1}\n\n" |
| 419 | "Command line: {2}\n\n" |
| 420 | "Environment variables: {3}\n\n", |
| 421 | self.debuggee_id, |
| 422 | json.repr(cwd), |
| 423 | json.repr(args), |
| 424 | json.repr(env), |
| 425 | ) |
| 426 | |
| 427 | popen_fds = {} |
| 428 | capture_fds = {} |
| 429 | for stream_name in self.captured_output: |
| 430 | rfd, wfd = os.pipe() |
| 431 | popen_fds[stream_name] = wfd |
| 432 | capture_fds[stream_name] = rfd |
| 433 | self.debuggee = psutil.Popen( |
| 434 | args, cwd=cwd, env=env, bufsize=0, stdin=subprocess.PIPE, **popen_fds |
| 435 | ) |
| 436 | log.info("Spawned {0} with PID={1}", self.debuggee_id, self.debuggee.pid) |
| 437 | watchdog.register_spawn(self.debuggee.pid, self.debuggee_id) |
| 438 | |
| 439 | if len(capture_fds): |
| 440 | self.captured_output = output.CapturedOutput(self, **capture_fds) |
| 441 | for fd in popen_fds.values(): |
| 442 | os.close(fd) |
| 443 | |
| 444 | def wait_for_adapter_socket(self): |
| 445 | log.info( |