-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add CommandExt::wait_with_output(self, timeout) #4
base: master
Are you sure you want to change the base?
Conversation
Unfortunately I don't think it's actually possible to do this atomically, at which point this probably shouldn't be exposed. If the wait times out then you probably don't want to capture output, and otherwise if you wait with a timeout then the process can deadlock because you're not reading the output (it needs to happen concurrently essentially) |
So how else can it be solved? I need to execute an user provided script that returns some result, but kill it when it hangs for whatever reason. |
You'd basically need to define your own semantics for what happens when the process times out. Do you throw away the input/output or send a kill signal? If you want to just kill it you can probably spawn two threads to read stdin/stdout, use the main thread to call |
If the process times out, then I don’t care about std{out,err} (however it may be useful to print stderr to log), just want to kill the process (it’s only a “safety net”). Spawning two threads just to read std{out,err} sounds like an overkill. |
The "overkill" here is required for correctness. This may work locally but as part of a library you can't read stdout/stderr only after the process exits. |
how about add this as a feature? |
FYI, I created a crate to do this: You can use |
@alexcrichton I’ll try to write smoke tests for this if you say that you wanna merge it.