Пример #1
0
    def spawn_adapter(self, args=()):
        assert self.adapter is None
        assert self.channel is None

        args = [sys.executable,
                os.path.dirname(debugpy.adapter.__file__)] + list(args)
        env = self._make_env(self.spawn_adapter.env)

        log.info(
            "Spawning {0}:\n\n"
            "Command line: {1!j}\n\n"
            "Environment variables: {2!j}\n\n",
            self.adapter_id,
            args,
            env,
        )
        self.adapter = psutil.Popen(
            args,
            bufsize=0,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            env=env.for_popen(),
        )
        log.info("Spawned {0} with PID={1}", self.adapter_id, self.adapter.pid)
        watchdog.register_spawn(self.adapter.pid, self.adapter_id)

        stream = messaging.JsonIOStream.from_process(self.adapter,
                                                     name=self.adapter_id)
        self._start_channel(stream)
Пример #2
0
 def _process_event(self, event):
     occ = self.timeline.record_event(event, block=False)
     if event.event == "exited":
         self.observe(occ)
         self.exit_code = event("exitCode", int)
         assert self.exit_code == self.expected_exit_code
     elif event.event == "debugpyAttach":
         self.observe(occ)
         pid = event("subProcessId", int)
         watchdog.register_spawn(
             pid, fmt("{0}-subprocess-{1}", self.debuggee_id, pid))
Пример #3
0
    def spawn_debuggee(self,
                       args,
                       cwd=None,
                       exe=sys.executable,
                       debug_me=None):
        assert self.debuggee is None
        assert not len(self.captured_output - {"stdout", "stderr"})

        args = [exe] + [
            compat.filename_str(
                s.strpath if isinstance(s, py.path.local) else s) for s in args
        ]

        cwd = compat.filename_str(cwd) if isinstance(cwd,
                                                     py.path.local) else cwd

        env = self._make_env(self.spawn_debuggee.env, codecov=False)
        env["PTVSD_ADAPTER_ENDPOINTS"] = self.adapter_endpoints = (
            self.tmpdir / "adapter_endpoints")
        if debug_me is not None:
            env["PTVSD_TEST_DEBUG_ME"] = debug_me

        log.info(
            "Spawning {0}:\n\n"
            "Current directory: {1!j}\n\n"
            "Command line: {2!j}\n\n"
            "Environment variables: {3!j}\n\n",
            self.debuggee_id,
            cwd,
            args,
            env,
        )

        popen_fds = {}
        capture_fds = {}
        for stream_name in self.captured_output:
            rfd, wfd = os.pipe()
            popen_fds[stream_name] = wfd
            capture_fds[stream_name] = rfd
        self.debuggee = psutil.Popen(args,
                                     cwd=cwd,
                                     env=env.for_popen(),
                                     bufsize=0,
                                     stdin=subprocess.PIPE,
                                     **popen_fds)
        log.info("Spawned {0} with PID={1}", self.debuggee_id,
                 self.debuggee.pid)
        watchdog.register_spawn(self.debuggee.pid, self.debuggee_id)

        if len(capture_fds):
            self.captured_output = output.CapturedOutput(self, **capture_fds)
        for fd in popen_fds.values():
            os.close(fd)
Пример #4
0
    def spawn_debuggee(self,
                       args,
                       cwd=None,
                       exe=sys.executable,
                       debug_me=None):
        assert self.debuggee is None

        args = [exe] + [
            compat.filename_str(
                s.strpath if isinstance(s, py.path.local) else s) for s in args
        ]

        cwd = compat.filename_str(cwd) if isinstance(cwd,
                                                     py.path.local) else cwd

        env = self._make_env(self.spawn_debuggee.env, codecov=False)
        env["PTVSD_LISTENER_FILE"] = self.listener_file = self.tmpdir / "listener"
        if debug_me is not None:
            env["PTVSD_TEST_DEBUG_ME"] = debug_me

        log.info(
            "Spawning {0}:\n\n"
            "Current directory: {1!j}\n\n"
            "Command line: {2!j}\n\n"
            "Environment variables: {3!j}\n\n",
            self.debuggee_id,
            cwd,
            args,
            env,
        )
        self.debuggee = psutil.Popen(
            args,
            cwd=cwd,
            env=env.for_popen(),
            bufsize=0,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        log.info("Spawned {0} with PID={1}", self.debuggee_id,
                 self.debuggee.pid)
        watchdog.register_spawn(self.debuggee.pid, self.debuggee_id)

        if self.captured_output:
            self.captured_output = output.CapturedOutput(self)