Skip to content

GH-124241: try reading /proc/self/exe to determine sys.executable#145486

Open
FFY00 wants to merge 1 commit intopython:mainfrom
FFY00:gh-124241
Open

GH-124241: try reading /proc/self/exe to determine sys.executable#145486
FFY00 wants to merge 1 commit intopython:mainfrom
FFY00:gh-124241

Conversation

@FFY00
Copy link
Member

@FFY00 FFY00 commented Mar 3, 2026

$ bash -c "exec -a echo $(pwd)/python -c 'import sys; print(sys.executable)'"
/home/anubis/git/cpython/python

Signed-off-by: Filipe Laíns <lains@riseup.net>
Comment on lines +268 to +273
if not executable and os_name == 'posix':
# On Linux, try resolving the executable path via procfs
try:
executable = realpath('/proc/self/exe')
except (OSError, MemoryError):
pass
Copy link
Member Author

Choose a reason for hiding this comment

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

Humm, perhaps we should do this after trying program_name, and only update the value if the executable path derived from program_name doesn't resolve to the same path as /proc/self/exe.

If progam_name is set and resolves to the same path as /proc/self/exe, honoring its value should be nicer.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant