Skip to content
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

Create a non-blocking wait() function for child processes. #1294

Closed
ZoeyR opened this issue Sep 25, 2015 · 6 comments
Closed

Create a non-blocking wait() function for child processes. #1294

ZoeyR opened this issue Sep 25, 2015 · 6 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@ZoeyR
Copy link

ZoeyR commented Sep 25, 2015

Currently the only way to wait on a child is to call wait() which blocks until the child has finished. For some applications, it is more useful to just check if the child has exited without blocking if it hasn't. Usage would be similar to this:

let child = Command::new("sleep").arg("10").spawn().unwrap();
child.wait_no_hang();
// Continue with execution even if child hasn't exited yet.
@BurntSushi
Copy link
Member

One possible low-tech solution to this problem is to just spawn your command in a separate thread and use a channel to communicate completion (which can be checked in a non-blocking fashion). This may not work for every use case, but I bet it's just fine for a majority of them. Otherwise, something like WNOHANG might be appropriate on unix. I don't know what the analogous option in Windows is.

@alexcrichton
Copy link
Member

Some time ago I actually wrote a crate for this, although it's generalized a bit more to a timeout as opposed to just a wait_no_hang. Thankfully this certainly can be implemented robustly across all platforms, so no Windows concerns!

I do think that our process management story needs to be beefed up a little for external extensions (where I think something like this should live first), but I certainly like the idea!

@LukasKalbertodt
Copy link
Member

cc me

@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Aug 22, 2016
@AkshatM
Copy link

AkshatM commented Jul 5, 2017

What is the current status of this RFC, please?

@LukasKalbertodt
Copy link
Member

I think this can be closed, now that Child::try_wait() is stable?

@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Closing per #1294 (comment).

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

7 participants