-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
os.pipe should return inheritable descriptors (Windows) #48958
Comments
os.pipe should return inheritable descriptors on Windows. Patch below, test attached. New pipe() returns descriptors, which Docs should contain a note to the effect. 'On Windows, use --- posixmodule_orig.c 2008-12-20 20:01:38.296875000 -0600
+++ posixmodule_new.c 2008-12-20 20:01:54.359375000 -0600
@@ -6481,8 +6481,12 @@
HANDLE read, write;
int read_fd, write_fd;
BOOL ok;
+ SECURITY_ATTRIBUTES sAttribs;
Py_BEGIN_ALLOW_THREADS
- ok = CreatePipe(&read, &write, NULL, 0);
+ sAttribs.nLength = sizeof( sAttribs );
+ sAttribs.lpSecurityDescriptor = NULL;
+ sAttribs.bInheritHandle = TRUE;
+ ok = CreatePipe(&read, &write, &sAttribs, 0);
Py_END_ALLOW_THREADS
if (!ok)
return win32_error("CreatePipe", NULL); |
From the thread in c.l.p: Pros (of changing os.pipe() to return inheritable pipes):
Cons:
|
Patch to posixmodule.c including test case and documentation updates. |
This is currently accomplished in 'multiprocessing.forking' with a Use (line #213):
Definition (line #192). Should it be included in the public interface and documented, or perhaps |
Victor, this fits nicely with your recent PEP. |
I disagree. On Windows fds can only be inherited if you start processes using the spanwn*() family of functions. If you start them using CreateProcess() then the underlying *handles* are inherited, but the *fds* are not. In Python 2, os.spawn*() used spawn*(), so making os.pipe() return inheritable fds would have made some sense. But in Python 3 os.spawn*() is implemented using subprocess/CreateProcess so fds will NOT be inherited (even if the wrapped handles are). Note that subprocess *does* know how to redirect the standard streams to fds returned by os.pipe(). So for Python 3 I don't think there is any point in changing things. |
Oops. I confused os.popen() with os.spawn*(). os.spawnv() IS still implemented using spawnv() in Python 3. |
Changing the default inheritance value of os.pipe() is not acceptable because it would break backward compatibility. Giving access to Windows extra parameter is nice, but we have to find a way to propose a portable API. That's what I'm trying to do with the PEP-446 (and it's previous version, the PEP-433). |
os.pipe() creates non-inheritable pipes on Windows, whereas it creates inheritable pipes on UNIX. IMO the reason is an implementation artifact: os.pipe() calls CreatePipe() on Windows (native API), whereas it calls pipe() on UNIX (POSIX API). The call to CreatePipe() was added in Python in 1994, before the introduction of pipe() in the POSIX API in Windows 98. |
The PEP-446 has been implemented in Python 3.4 and all file descriptors and sockets are now created non-inheritable by default. Use os.set_inheritable() to make the pipe fds inheritable. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: