std: Add a nonblocking Child::try_wait method#38866
Merged
bors merged 1 commit intorust-lang:masterfrom Jan 9, 2017
Merged
Conversation
Contributor
|
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
Member
Author
|
API-wise I was torn between returning |
Contributor
|
@bors: r+ |
Collaborator
|
📌 Commit 0048bf3 has been approved by |
Contributor
|
@bors: r- Sorry, needs to have a tracking issue first. But this LGTM. |
This commit adds a new method to the `Child` type in the `std::process` module called `try_wait`. This method is the same as `wait` except that it will not block the calling thread and instead only attempt to collect the exit status. On Unix this means that we call `waitpid` with the `WNOHANG` flag and on Windows it just means that we pass a 0 timeout to `WaitForSingleObject`. Currently it's possible to build this method out of tree, but it's unfortunately tricky to do so. Specifically on Unix you essentially lose ownership of the pid for the process once a call to `waitpid` has succeeded. Although `Child` tracks this state internally to be resilient to multiple calls to `wait` or a `kill` after a successful wait, if the child is waited on externally then the state inside of `Child` is not updated. This means that external implementations of this method must be extra careful to essentially not use a `Child`'s methods after a call to `waitpid` has succeeded (even in a nonblocking fashion). By adding this functionality to the standard library it should help canonicalize these external implementations and ensure they can continue to robustly reuse the `Child` type from the standard library without worrying about pid ownership.
Member
Author
|
@bors: r=aturon |
Collaborator
|
📌 Commit abb9189 has been approved by |
Collaborator
|
⌛ Testing commit abb9189 with merge 7e7a00c... |
Collaborator
|
💔 Test failed - status-travis |
Member
Author
|
@bors: retry
* osx linker segfaulted
…On Sun, Jan 8, 2017 at 3:00 PM, bors ***@***.***> wrote:
💔 Test failed - status-travis
<https://travis-ci.org/rust-lang/rust/builds/190079741>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#38866 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95PDLjudA-GStT_K-nGYn7QU9IYFbks5rQWqbgaJpZM4LcdKN>
.
|
Collaborator
bors
added a commit
that referenced
this pull request
Jan 9, 2017
std: Add a nonblocking `Child::try_wait` method This commit adds a new method to the `Child` type in the `std::process` module called `try_wait`. This method is the same as `wait` except that it will not block the calling thread and instead only attempt to collect the exit status. On Unix this means that we call `waitpid` with the `WNOHANG` flag and on Windows it just means that we pass a 0 timeout to `WaitForSingleObject`. Currently it's possible to build this method out of tree, but it's unfortunately tricky to do so. Specifically on Unix you essentially lose ownership of the pid for the process once a call to `waitpid` has succeeded. Although `Child` tracks this state internally to be resilient to multiple calls to `wait` or a `kill` after a successful wait, if the child is waited on externally then the state inside of `Child` is not updated. This means that external implementations of this method must be extra careful to essentially not use a `Child`'s methods after a call to `waitpid` has succeeded (even in a nonblocking fashion). By adding this functionality to the standard library it should help canonicalize these external implementations and ensure they can continue to robustly reuse the `Child` type from the standard library without worrying about pid ownership.
Collaborator
|
☀️ Test successful - status-appveyor, status-travis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds a new method to the
Childtype in thestd::processmodulecalled
try_wait. This method is the same aswaitexcept that it will notblock the calling thread and instead only attempt to collect the exit status. On
Unix this means that we call
waitpidwith theWNOHANGflag and on Windows itjust means that we pass a 0 timeout to
WaitForSingleObject.Currently it's possible to build this method out of tree, but it's unfortunately
tricky to do so. Specifically on Unix you essentially lose ownership of the pid
for the process once a call to
waitpidhas succeeded. AlthoughChildtracksthis state internally to be resilient to multiple calls to
waitor akillafter a successful wait, if the child is waited on externally then the state
inside of
Childis not updated. This means that external implementations ofthis method must be extra careful to essentially not use a
Child's methodsafter a call to
waitpidhas succeeded (even in a nonblocking fashion).By adding this functionality to the standard library it should help canonicalize
these external implementations and ensure they can continue to robustly reuse
the
Childtype from the standard library without worrying about pid ownership.