GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `_remote_debugging`: `get_child_pids()` iterates all processes four times · Issue #156060 · python/cpython

_remote_debugging: get_child_pids() iterates all processes four times #156060

New issue
Copy link
New issue
Copy link
Closed
#156061
Closed
_remote_debugging: get_child_pids() iterates all processes four times#156060
#156061
Copy link
Labels
OS-macextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@maurycy
maurycy
opened on Aug 19, 2026
Issue body actions

Bug report

Bug description:

Found while trying to understand the gcmon performance in #155828 (comment).

We treat proc_listpids() as a number of PIDs:

cpython/Modules/_remote_debugging/subprocess.c

Line 305 in 10a8454

int n_pids = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0);

cpython/Modules/_remote_debugging/subprocess.c

Line 320 in 10a8454

int actual = proc_listpids(PROC_ALL_PIDS, 0, pid_list, buffer_size * sizeof(pid_t));

cpython/Modules/_remote_debugging/subprocess.c

Line 335 in 10a8454

for (int i = 0; i < actual; i++) {

...but it returns a number of bytes:

https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/libsyscall/wrappers/libproc/libproc.c#L62-L73

sizeof(pid_t) == 4, so it does 4x times more work than it needs to be.

This was changed in #144648.

Reproduction

2026-08-19T18:53:44.066591000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main f40043e*?) % ps axlww | wc -l
     996
2026-08-19T18:53:46.142930000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main f40043e*?) % sudo dtrace -q -n 'pid$target::proc_pidinfo:entry { @ = count(); }' -c "./python.exe repro.py"

             3996

for

import _remote_debugging, os
_remote_debugging.get_child_pids(os.getpid(), recursive=True)

Fix

I believe the simplest fix should be along the lines of:

int n_pids = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0) / sizeof(pid_t);
...
int actual = proc_listpids(PROC_ALL_PIDS, 0, pid_list,
                            buffer_size * sizeof(pid_t)) / sizeof(pid_t);

(not exactly like that because proc_listpids() can return -1).

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

  • gh-156060: Do not scan every process four times in remote_debugging.get_child_pids() on macOS #156061
  • [3.15] gh-156060: Do not scan every process four times in remote_debugging.get_child_pids() on macOS (GH-156061) #156069

Activity

  1. maurycy
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Aug 19, 2026
  2. aisk
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    OS-mac
    on Aug 19, 2026
  3. sergey-miryanov commented on Aug 19, 2026

    @sergey-miryanov
    sergey-miryanov
    on Aug 19, 2026
    Contributor
    More actions

    Good catch!

    Reacted by Maurycy Pawłowski-Wieroński
  4. pablogsal
    added a commit that references this issue on Aug 19, 2026

    gh-156060: Do not scan every process four times in `remote_debugging.…

    a2c9a3b
  5. pablogsal
    closed this as completedin #156061on Aug 19, 2026
  6. pablogsal
    added a commit that references this issue on Aug 19, 2026

    [3.15] gh-156060: Do not scan every process four times in `remote_deb…

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-macextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.