Skip to content

python on Windows closes additional file descriptors on launch #104099

@dnschneid

Description

@dnschneid

Bug report

If you launch python with additional fds open (e.g., 3 and 4 for a pipe), python on Windows seems to close the pipes on launch, but on Linux you can use them just fine. I ran into this when debugging a python integration with a third-party tool; the integration worked on Linux but not on Windows, but after digging I could not find any way to launch python with the additional fds preserved on Windows.

test.py:

import os
os.write(3, b'ok\n')

Run:

python3 test.py 3>&1

On linux, if you run the command above, you'll get "ok" written out on stdout. On Windows, it'll be as if you didn't do the redirection, and you'll get
OSError: [Errno 9] Bad file descriptor

As a sanity-check, I did try launching other processes that can use the additional file descriptors, such as

test_notpy.sh:

echo ok >&3

Run:

bash test_notpy.sh 3>&1

and file descriptor passing does seem like it should work on Windows.

The third-party integration is also advertised to work just fine on Windows, so that's another data point that it's not my test cases doing lots of cartwheels behind the scenes to make it look like it's working. So I'm probably not crazy, although I wouldn't be surprised if I'm missing something since this seems like it should be pretty basic behavior...

Your environment

Tested on Windows 10, x86_64, with the 3.11 python in the windows store as well as with the Python 3.10.11 on the python.org download page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions