Skip to content

Windows implementation of set_close_exec will not work #2867

@zooba

Description

@zooba

The Windows implementation of set_close_exec https://github.com/tornadoweb/tornado/blob/master/tornado/platform/windows.py currently can never work because SetHandleInformation needs an OS handle, but everywhere this function is called it is given a file descriptor.

Firstly, I believe that by default all handles are non-inheritable. But I haven't checked everywhere you're creating them though - certainly the returned pipes from os.pipe are explicitly noninheritable.

Most likely you should just use os.set_inheritable on all platforms, which does what you need. It was added in Python 3.4, so once 2.7 is no longer a concern this is probably the easiest way forward. It knows how to convert FDs to handles on Windows.

Finally, I came across this because I'm trying to bring up a Python environment on Windows that doesn't include ctypes, and this showed up on my list of "concerns". I'll patch my own to use the builtin function, but figured I'd mention that the current code doesn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions