Skip to content

Conversation

@jborean93
Copy link
Contributor

Add the ability to specify the parent process id when connecting a new DAP server to the client. This value is used instead of the actual process' parent id so that it can be associated with a specific debug session even if it hasn't been spawned directly by that parent process.

Fixes: #1918

I can update the wiki pages with the new argument/kwarg once this is merged.

Add the ability to specify the parent process id when connecting a new
DAP server to the client. This value is used instead of the actual
process' parent id so that it can be associated with a specific debug
session even if it hasn't been spawned directly by that parent process.
@jborean93 jborean93 requested a review from a team as a code owner July 3, 2025 23:08
@rchiodo
Copy link
Contributor

rchiodo commented Jul 3, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

"port": int(port),
"multiprocess": patch_multiprocessing,
"skip-notify-stdin": not notify_stdin,
pydevd_constants.ARGUMENT_PPID: ppid,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this only be set if ppid is not zero?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, no it looks like it would get picked up here if the argument is zero:

    def on_pydevdsysteminfo_request(self, py_db, request):
        try:
            pid = os.getpid()
        except AttributeError:
            pid = None

        # It's possible to have the ppid reported from args. In this case, use that instead of the
        # real ppid (athough we're using `ppid`, what we want in meaning is the `launcher_pid` --
        # so, if a python process is launched from another python process, consider that process the
        # parent and not any intermediary stubs).

        ppid = py_db.get_arg_ppid() or self.api.get_ppid() <== This should ignore it if zero

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, the pydevd CLI sets ppid to a default of 0, this just replicates that same functionality but through the settrace API call.

@jborean93
Copy link
Contributor Author

I've also opened a PR on PyDevD upstream with the changes I've made in the vendored copy fabioz/PyDev.Debugger#309.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 3, 2025

Thanks for the PR.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 3, 2025

A test would be nice for this option, but it might be hard to get the intermediate process to launch debugpy in the test.

This file would be the likely spot for a test:
tests\debugpy\server\test_cli.py

@jborean93
Copy link
Contributor Author

I'll try and add one, I'm not going to lie the workflow for this scenario is complex but I'll see how I go :)

@jborean93
Copy link
Contributor Author

I've added a test for this scenario that I believe covers what this is trying to solve. The wait_for_next_subprocess call verifies that the Python grandchild process is associated with the parent's debug session through the --parent-session-pid argument. It spawns the grandchild process through a shell ensuring that it doesn't inherit the session just by being the child of the launch Python process.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 7, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. LGTM

@rchiodo rchiodo merged commit b387710 into microsoft:main Jul 7, 2025
22 of 24 checks passed
@rchiodo
Copy link
Contributor

rchiodo commented Jul 7, 2025

I'm hoping to release before 3.14 goes GA. We still need to do some more testing/work around 3.14, but waiting for it to settle down a bit.

@jborean93 jborean93 deleted the parent-pid branch July 7, 2025 18:26
@jborean93
Copy link
Contributor Author

Appreciate the guidance and review. Hoping to solve this one today or tomorrow as well #1876 (comment). We are about to bump our minimum dep to 3.12+ so I can no longer rely on using 3.11 to debug our forked worker properly.

@jborean93
Copy link
Contributor Author

Sorry I know I said I was going to update the wiki with the new CLI arg and API kwarg but it looks like you need to be a maintainer for this repo to make changes there.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 8, 2025

Sorry I know I said I was going to update the wiki with the new CLI arg and API kwarg but it looks like you need to be a maintainer for this repo to make changes there.

Oh thanks for checking. I can do that then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New child process spawned with debugpy --connect not receiving breakpoints

2 participants