You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Newly added test_cmd_line_script.test_script_as_dev_fd() fails on FreeBSD: /dev/fd/3 doesn't exist #100005
FreeBSD /dev/fd/ behaves differently than Linux /dev/fd/. I'm not sure why. If the parent opens a file and the file descriptor is inherited, the child process can open the file, but /dev/fd/ only contains file descriptors 0, 1, 2. Example:
parent.py:
import subprocess
import sys
script = 'print("Hello")'
script_name = 'script.py'
with open(script_name, 'w') as fp:
fp.write(script)
with open(script_name, "r") as fp:
fd = fp.fileno()
print("FD", fd)
cmd = [sys.executable]
p = subprocess.Popen(cmd, close_fds=False, pass_fds=(0, 1, 2, fd))
p.wait()
Child process:
$ ./python y.py
FD 3
/usr/home/vstinner/python/main/Lib/subprocess.py:849: RuntimeWarning: pass_fds overriding close_fds.
warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)
Python 3.12.0a2+ (heads/main:e3a3863cb9, Dec 5 2022, 12:09:39) [Clang 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a3 on freebsd13
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
# The process has 4 file descriptors:
>>> fd=os.dup(0); os.close(fd)
>>> fd=os.dup(1); os.close(fd)
>>> fd=os.dup(2); os.close(fd)
>>> fd=os.dup(3); os.close(fd)
# But /dev/fd/3 doesn't exist
>>> os.listdir("/dev/fd")
['0', '1', '2']
>>> f=open("/dev/fd/3", "rb")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/dev/fd/3'
# Using directly file descriptor 3 works as expected:
>>> f=open(3, "rb")
>>> f.close()
Activity
gh-100005: Skip test_script_as_dev_fd() on FreeBSD (#100006)
pythongh-100005: Skip test_script_as_dev_fd() on FreeBSD (pythonGH-10…
gh-100005: Skip test_script_as_dev_fd() on FreeBSD (GH-100006)
vstinner commentedon Dec 5, 2022
Fixed by 038b151
pythongh-100005: Skip test_script_as_dev_fd() on FreeBSD (pythonGH-10…
[3.10] gh-100005: Skip test_script_as_dev_fd() on FreeBSD (GH-100006) (…