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

Expand on using stdin / stdout #85

Open
carllerche opened this issue Nov 19, 2018 · 3 comments
Open

Expand on using stdin / stdout #85

carllerche opened this issue Nov 19, 2018 · 3 comments
Labels
confusion Something caused a user confusion question Further information is requested

Comments

@carllerche
Copy link
Member

Related: tokio-rs/tokio#709

@k4210
Copy link

k4210 commented Aug 27, 2019

Hi,
@carllerche could you elaborate? Isn't the purpose of tokio stdin to be non-blocking?
By FD you mean file descriptor ?
Cheers!

@benkay86
Copy link

benkay86 commented Feb 4, 2020

Per discussion on discord #tokio-users, the documentation for stdin may be using the word "block" loosely. As currently written:

As an additional caveat, reading from the handle may block the calling future indefinitely if there is not enough data available.

I am not sure if my interpretation is entirely accurate, but it might have been clearer to write:

The standard input is more likely to have incomplete data than most objects implementing AsyncRead because it often depends on the user (a human being) for input. Although a call to AsyncRead::poll_read() will not block, code awaiting a future (e.g. AsyncReadExt::read_to_end().await) may wait indefinitely if there is not enough data available. Consider wrapping such calls in a tokio::timeout.

@jebrosen
Copy link

jebrosen commented Feb 4, 2020

As an additional caveat, reading from the handle may block the calling future indefinitely if there is not enough data available. This makes this handle unsuitable for use in any circumstance where immediate reaction to available data is required, e.g. interactive use or when implementing a subprocess driven by requests on the standard input.

On the contrary, this seems like desired behavior to me. Reads will wait (they will not block in the "blocking" sense that should be avoided in async code) for data to be available: stdin.read().await will not complete until the user or calling program has "entered" input (possibly only at a newline depending on terminal emulation and all that jazz), just like the synchronous version would.

EDIT: Accidentally pressed Ctrl+Enter.

hawkw added a commit to tokio-rs/tokio that referenced this issue Feb 17, 2020
Currently, the `tokio::sync::RwLock` docs refer to tasks waiting to
acquire a lock as "blocking". This is because these docs were copied
from the `std::sync::RwLock` docs. In the past, the use of the term
"blocking" to refer to causing a thread to yield [has caused confusion
for users][1].

This commit changes the `RwLock` documentation to use the terms "yields"
and "causing a task to yield" rather than "blocks" or "blocking a task".
This should make the documentation less ambiguous, so that users don't
incorrectly interpret this as stating that the use of `RwLock` will
block a thread.

[1]: tokio-rs/doc-push#85 (comment)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@ultrasaurus ultrasaurus added the question Further information is requested label Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confusion Something caused a user confusion question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants