Skip to content

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

Open
tanloong wants to merge 6 commits into
python:mainfrom
tanloong:162251
Open

tanloong wants to merge 6 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
"""
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

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

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants