-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-87235: Make sure "python /dev/fd/9 9</path/to/script.py" works on macOS #99768
GH-87235: Make sure "python /dev/fd/9 9</path/to/script.py" works on macOS #99768
Conversation
…ks on macOS On macOS all file descriptors for a particular file in /dev/fd share the same file offset, that is ``open("/dev/fd/9", "r")`` behaves more like ``dup(9)`` than a regular open. This causes problems when a user tries to run "/dev/fd/9" as a script because zipimport changes the file offset to try to read a zipfile directory. Therefore change zipimport to reset the file offset after trying to read the zipfile directory.
try: | ||
fp.seek(-END_CENTRAL_DIR_SIZE, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks messy here. I just indented the body of "with fp" one level deeper to add the code to reset the file offset, that is:
start_offset = fp.tell()
try:
<ORIGINAL CODE>
finally:
fp.seek(start_offset)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a hack to me, but I do not know a better solution.
Thanks @ronaldoussoren for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
GH-99816 is a backport of this pull request to the 3.11 branch. |
…ks on macOS (pythonGH-99768) On macOS all file descriptors for a particular file in /dev/fd share the same file offset, that is ``open("/dev/fd/9", "r")`` behaves more like ``dup(9)`` than a regular open. This causes problems when a user tries to run "/dev/fd/9" as a script because zipimport changes the file offset to try to read a zipfile directory. Therefore change zipimport to reset the file offset after trying to read the zipfile directory. (cherry picked from commit d08fb25) Co-authored-by: Ronald Oussoren <[email protected]>
…ks on macOS (pythonGH-99768) On macOS all file descriptors for a particular file in /dev/fd share the same file offset, that is ``open("/dev/fd/9", "r")`` behaves more like ``dup(9)`` than a regular open. This causes problems when a user tries to run "/dev/fd/9" as a script because zipimport changes the file offset to try to read a zipfile directory. Therefore change zipimport to reset the file offset after trying to read the zipfile directory. (cherry picked from commit d08fb25) Co-authored-by: Ronald Oussoren <[email protected]>
GH-99817 is a backport of this pull request to the 3.10 branch. |
…macOS (GH-99768) On macOS all file descriptors for a particular file in /dev/fd share the same file offset, that is ``open("/dev/fd/9", "r")`` behaves more like ``dup(9)`` than a regular open. This causes problems when a user tries to run "/dev/fd/9" as a script because zipimport changes the file offset to try to read a zipfile directory. Therefore change zipimport to reset the file offset after trying to read the zipfile directory. (cherry picked from commit d08fb25) Co-authored-by: Ronald Oussoren <[email protected]>
…rks on macOS (GH-99768) (#99817) On macOS all file descriptors for a particular file in /dev/fd share the same file offset, that is ``open("/dev/fd/9", "r")`` behaves more like ``dup(9)`` than a regular open. This causes problems when a user tries to run "/dev/fd/9" as a script because zipimport changes the file offset to try to read a zipfile directory. Therefore change zipimport to reset the file offset after trying to read the zipfile directory. (cherry picked from commit d08fb25) Co-authored-by: Ronald Oussoren <[email protected]> * Regen zipimport --------- Co-authored-by: Ronald Oussoren <[email protected]> Co-authored-by: Shantanu <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
On macOS all file descriptors for a particular file in /dev/fd share the same file offset, that is
open("/dev/fd/9", "r")
behaves more likedup(9)
than a regular open.This causes problems when a user tries to run "/dev/fd/9" as a script because zipimport changes the file offset to try to read a zipfile directory. Therefore change zipimport to reset the file offset after trying to read the zipfile directory.
/dev/fd/X
#87235