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
[Windows] subprocess: close the handle when the process completes #81591
Comments
subprocess.Popen uses _winapi.CreateProcess() to spawn a child process. It stores the process handle using a Handle class. Popen never explicitly releases the handle, it rely on Handle.__del__ when the Popen object is detroyed (when Popen._handle attribute is cleared). As discussed in bpo-37380, we could call explicitly CloseHandle(handle) as soon as the child process completes, to release resources in the Windows kernel. Attached PR implements this fix. |
IMHO it's safe to backport PR 14391 to Python 3.7 and 3.8. |
See also bpo-37380: subprocess.Popen._cleanup() "The handle is invalid" error when some old process is gone. |
We may backport the change to Python 2.7 as well, but in this case terminate() must be changed to test returncode: def terminate(self):
"""Terminates the process."""
# Don't terminate a process that we know has already died.
if self.returncode is not None:
return
... |
terminate() was changed by: commit a0c9caa
|
Sadly, I don't have the bandwidth to work on this issue, I just close it. |
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: