-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
std: Add a nonblocking Child::try_wait
method
#38866
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
API-wise I was torn between returning |
@bors: r+ |
📌 Commit 0048bf3 has been approved by |
@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.
@bors: r=aturon |
📌 Commit abb9189 has been approved by |
⌛ Testing commit abb9189 with merge 7e7a00c... |
💔 Test failed - status-travis |
@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>
.
|
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.
☀️ Test successful - status-appveyor, status-travis |
This commit adds a new method to the
Child
type in thestd::process
modulecalled
try_wait
. This method is the same aswait
except that it will notblock the calling thread and instead only attempt to collect the exit status. On
Unix this means that we call
waitpid
with theWNOHANG
flag 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
waitpid
has succeeded. AlthoughChild
tracksthis state internally to be resilient to multiple calls to
wait
or akill
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 ofthis method must be extra careful to essentially not use a
Child
's methodsafter 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.