Prevent Python subprocess from passing fds on Windows?
The Python subprocess module, by default, passes all open file descriptors to any child processes it spawns. This means that if the parent process is listening on a port and is killed, it cannot restart and start listening again (even using SO_REUSEADDR) because the child still has that handle. I have no control over the child process.
The subprocess POpen constructor takes a close_fds argument, which closes the handles for the child as I want. However, there is a Windows-only limitation that prevents it from being used if stdin / stdout is also overridden, which is what I need to do.
Does anyone know of this to work on Windows?
source to share
What seems to be the most relevant information I can find is: The SetHandleInformation that this article is linking to should give you pointers.
You will probably need to use pywin32 and / or ctypes to accomplish what you want.
source to share