-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
bpo-37380: subprocess: skip _cleanup and __del__ on win #14360
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,22 +218,38 @@ def __repr__(self): | |
| _PopenSelector = selectors.SelectSelector | ||
|
|
||
|
|
||
| # This lists holds Popen instances for which the underlying process had not | ||
| # exited at the time its __del__ method got called: those processes are wait()ed | ||
| # for synchronously from _cleanup() when a new Popen object is created, to avoid | ||
| # zombie processes. | ||
| _active = [] | ||
|
|
||
| def _cleanup(): | ||
| for inst in _active[:]: | ||
| res = inst._internal_poll(_deadstate=sys.maxsize) | ||
| if res is not None: | ||
| try: | ||
| _active.remove(inst) | ||
| except ValueError: | ||
| # This can happen if two threads create a new Popen instance. | ||
| # It's harmless that it was already removed, so ignore. | ||
| pass | ||
| if _mswindows: | ||
| # On Windows we just need to close `Popen._handle` when we no longer need | ||
| # it, so that the kernel can free it. `Popen._handle` gets closed | ||
| # implicitly when the `Popen` instance is finalized (see `Handle.__del__`, | ||
| # which is calling `CloseHandle` as requested in [1]), so there is nothing | ||
| # for `_cleanup` to do. | ||
| # | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM. FYI, if bpo37410 is resolved, we'll also be explicitly closing |
||
| # [1] https://docs.microsoft.com/en-us/windows/desktop/ProcThread/ | ||
| # creating-processes | ||
| _active = None | ||
|
|
||
| def _cleanup(): | ||
| pass | ||
| else: | ||
| # This lists holds Popen instances for which the underlying process had not | ||
| # exited at the time its __del__ method got called: those processes are | ||
| # wait()ed for synchronously from _cleanup() when a new Popen object is | ||
| # created, to avoid zombie processes. | ||
| _active = [] | ||
|
|
||
| def _cleanup(): | ||
| if _active is None: | ||
| return | ||
| for inst in _active[:]: | ||
| res = inst._internal_poll(_deadstate=sys.maxsize) | ||
| if res is not None: | ||
| try: | ||
| _active.remove(inst) | ||
| except ValueError: | ||
| # This can happen if two threads create a new Popen instance. | ||
| # It's harmless that it was already removed, so ignore. | ||
| pass | ||
|
|
||
| PIPE = -1 | ||
| STDOUT = -2 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Don't collect unfinished processes with ``subprocess._active`` on Windows to | ||
| cleanup later. Patch by Ruslan Kuprieiev. |
Uh oh!
There was an error while loading. Please reload this page.