Skip to content

gh-162251: Wait for child execve before creating RemoteUnwinder - #162268

Merged
vstinner merged 10 commits into
python:mainfrom
tanloong:162251
Nov 20, 2026
Merged

vstinner merged 10 commits into
python:mainfrom
tanloong:162251

Conversation

@tanloong

@tanloong tanloong commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explained in #162251 (comment).

Adds socket communication following the pattern used by other tests in test_external_inspection.py. I confirmed the timeout error appears on main and disappears with the change.

@tanloong tanloong changed the title gh-162251: Wait for child execve signal before creating RemoteUnwinder gh-162251: Wait for child execve before creating RemoteUnwinder Nov 19, 2026
Comment thread Lib/test/test_external_inspection.py Resolved
Comment thread Lib/test/test_external_inspection.py Outdated
"""
with _managed_subprocess([sys.executable, "-c", script]) as process:
# On Linux, wait until execve() replaced the forked process image.
if sys.platform == "linux":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice if we could find a portable solution to fix also the issue on other platforms.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I think the portable solution is the earlier socket-communication version in this PR. The child sends a b"ready" signal, which can only happen after execve(). It works on Linux/macOS/Windows. I'm happy to switch back to that version if you prefer portability.

Co-authored-by: Victor Stinner <vstinner@python.org>
@maurycy

maurycy commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@tanloong @vstinner Can we try self._target_process instead of _managed_subprocess?

with self._target_process(script) as (process, _, _):
    unwinder = RemoteUnwinder(
        process.pid, native=True, gc=False, cache_frames=False,
    )

Also, getting rid of the whole for _ in busy_retry(SHORT_TIMEOUT) loop.

cc @pablogsal

@tanloong

Copy link
Copy Markdown
Contributor Author

@maurycy That's much cleaner! I'd like to switch to _target_process and drop busy_retry() loop. But will wait for @vstinner's opinion. cc @pablogsal

@vstinner

Copy link
Copy Markdown
Member

_target_process() API looks cleaner and more portable than reading /proc/pid/cmdline. Yeah we should reuse that.

@tanloong

tanloong commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated to reuse _target_process() and removed busy_retry loop in 018e1ec.

There are other places in test_external_inspection.py that can also be switched to reuse _target_process() to avoid redundant code, I am happy to do that in a separate PR.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

You might reuse _target_process() make_unwinder (3rd argument), but it would require to add new optional arguments to make_unwinder(). I'm not sure that it's worth it. It's ok to use RemoteUnwinder directly.

It seems like only test_popping_python_frame_is_not_native() used directly _managed_subprocess() without synchronization with the child process. So we should be good with this change.

@vstinner

Copy link
Copy Markdown
Member

Python 3.15 is not affected: it doesn't have the test.

@vstinner
vstinner merged commit 921de8f into python:main Nov 20, 2026
55 checks passed
@vstinner

Copy link
Copy Markdown
Member

Merged. Thanks for the fix!

@tanloong
tanloong deleted the 162251 branch November 21, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants