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

process: document how to read output from Child #7138

Closed
dan-da opened this issue Feb 4, 2025 · 6 comments · Fixed by #7141
Closed

process: document how to read output from Child #7138

dan-da opened this issue Feb 4, 2025 · 6 comments · Fixed by #7141
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-process Module: tokio/process T-docs Topic: documentation

Comments

@dan-da
Copy link

dan-da commented Feb 4, 2025

tokio v1.41.0
ubuntu linux 22.04

Description

Child::wait_with_output() should take &mut self instead of self. Taking self means it cannot be used in a select!(), which means there is no good way to simultaneously wait for a child processes output and a kill/cancel channel message.

stated differently, the docs for Child::kill() provide an example of using select!() with branches for Child::wait() and a oneshot channel recv(). This example works perfectly for Child::wait() but fails to compile for Child::wait_with_output().

The only way I was able to get it to work was to copy/paste the impl of Child::wait_with_output() into my own code and modify it to take &mut self instead.

See discussion #7132 with playground examples.

@dan-da dan-da added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Feb 4, 2025
@Darksonn Darksonn added the M-process Module: tokio/process label Feb 5, 2025
@Darksonn
Copy link
Contributor

Darksonn commented Feb 5, 2025

This function cannot be changed due to backwards compatibility.

@dan-da
Copy link
Author

dan-da commented Feb 5, 2025

that sounds like a good reason to never change anything.

@Darksonn
Copy link
Contributor

Darksonn commented Feb 5, 2025

Not making changes that break existing code is absolutely fundamental to maintain a library. We can add new methods, but we cannot delete methods or change their signature.

@dan-da
Copy link
Author

dan-da commented Feb 5, 2025

Let's reframe as a question then:

how can an application use the tokio library to await output of a child process, and simultaneously listen for a message to kill that process? The example given for Child::kill() does not read child's output, and does not compile if Child::wait_with_output() is substituted for Child::wait().

If a simple example can be created with present API, then let's add it to the Child::kill() docs, and this can be closed. Otherwise, it seems some change (or addition) to the API must be needed. no?

@Darksonn
Copy link
Contributor

Darksonn commented Feb 6, 2025

Reading the child's output is of course possible, and I'm happy to see such an example. Unfortunately, I don't have time to write it right now.

@Darksonn Darksonn added E-help-wanted Call for participation: Help is requested to fix this issue. T-docs Topic: documentation labels Feb 6, 2025
@Darksonn Darksonn changed the title Child::wait_with_output() cannot be used in conjunction with Child::kill() process: document how to read output from Child Feb 6, 2025
@dan-da
Copy link
Author

dan-da commented Feb 7, 2025

@maminrayej thanks for the PR. very helpful example!

@Darksonn Darksonn removed the E-help-wanted Call for participation: Help is requested to fix this issue. label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-process Module: tokio/process T-docs Topic: documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants