-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Subprocess timeout causes output to be returned as bytes in text mode #87597
Comments
Passing the argument However, if you give a timeout and that timeout expires, the raised Test output: |
communicate() is incomplete, so decoding the output may fail. For example, say the encoding is UTF-8, and the last multibyte character sequence (2-4 bytes) is incomplete. Maybe communicate() should always set In Windows, run() tries to complete communication, which is dysfunctional in cases. I created bpo-43346 to propose changing the design in Windows, in order to address 3 cases that can cause subprocess.run() to ignore the given timeout. The proposed change also sets an incomplete read of stdout and stderr as bytes objects, regardless of text mode, because I was simply matching what POSIX does in this case. |
Eryk Sun: Well, I think step 1 should be to update the documentation for Python 3.7 through 3.10 on If we went with the model of having |
Note: If you use |
There's another related bug here: when there's no output before the timeout is hit then you get the |
Unfortunately this counts as an API change as people will have written code since timeouts were introduced in 3.3 that blindly assumes TimeoutExpired.stdout/stderr are bytes. So while it might be a bug, it's also a breaking change and thus feature. Meaning it can't be backported. And likely needing a deprecation period. |
This documents the behavior that has always been the case since timeout support was introduced in Python 3.3.
This documents the behavior that has always been the case since timeout support was introduced in Python 3.3.
…nGH-97685) This documents the behavior that has always been the case since timeout support was introduced in Python 3.3. (cherry picked from commit b05dd79) Co-authored-by: Gregory P. Smith <[email protected]>
…nGH-97685) This documents the behavior that has always been the case since timeout support was introduced in Python 3.3. (cherry picked from commit b05dd79) Co-authored-by: Gregory P. Smith <[email protected]>
…nGH-97685) This documents the behavior that has always been the case since timeout support was introduced in Python 3.3. (cherry picked from commit b05dd79) Co-authored-by: Gregory P. Smith <[email protected]>
This documents the behavior that has always been the case since timeout support was introduced in Python 3.3. (cherry picked from commit b05dd79) Co-authored-by: Gregory P. Smith <[email protected]>
This documents the behavior that has always been the case since timeout support was introduced in Python 3.3. (cherry picked from commit b05dd79) Co-authored-by: Gregory P. Smith <[email protected]>
…n#97685) This documents the behavior that has always been the case since timeout support was introduced in Python 3.3.
) (GH-97688) This documents the behavior that has always been the case since timeout support was introduced in Python 3.3. (cherry picked from commit b05dd79) Co-authored-by: Gregory P. Smith <[email protected]>
See python/cpython#97685 The union type should be acceptable given python/cpython#87597 (comment). In general I'd like us to be able to type this, since these being bytes can be surprising if you pass text=True, but we'll see what mypy_primer says
This documents the behavior that has always been the case since timeout support was introduced in Python 3.3. (cherry picked from commit b05dd79) Co-authored-by: Gregory P. Smith <[email protected]>
The current behaviour was documented in ...: Unless there is a need for a breaking change, I suggest closing this as resolved. |
I don't think this should be closed, from my perspective this is just a bug, and should not have been documented as now changing it would be a breaking change (which would still be warranted in my opinion). I raised a PR addressing this (#95579 - not sure why it was moved to draft state), and a discussion following the pushback (https://discuss.python.org/t/pr-review-request-decode-subprocess-output-in-text-mode-when-timeout-is-hit/19594/2) which didn't get any input. This feels very much unfinished to me, and unfortunately remains an ugly wart for users who want to properly handle errors when using subprocess (especially in combination with mypy for type checking). |
I understand your frustration, but existing code already depends on the behavior given it has been this way for 11+ years now so it isn't "just a bug" in that sense - thus documenting the existing behavior to save everyone the trouble of discovering it the hard way. I moved that PR to Draft as most PRs should really just start in Draft mode (a realtively new-to-github feature, we should use it more often) as that helps indicate that there are unresolved larger issues and it is unclear if the change as is, is even what we want. See my #95579 (comment) comment. It sounds like there is a potential way forward based on the last comment from @zooba on the PR - keeping both the bytes and decoding to text on demand via a new TimeoutExpired attribute for the purpose. I'm fine reopening this since you seem interested in working on 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: