Skip to content

tokio::select! blocks when using tokio::io::Lines::next_line() #5684

Answered by Darksonn
acheronfail asked this question in Q&A
Discussion options

You must be logged in to vote

When you return from main, Tokio will attempt to kill and then wait for background tasks before it exits. However, the background task that reads from stdin is impossible to kill, so Tokio is forced to wait until it returns normally.

I recommend following the recommendation from the documentation:

This handle is best used for non-interactive uses, such as when a file is piped into the application. For technical reasons, stdin is implemented by using an ordinary blocking read on a separate thread, and it is impossible to cancel that read. This can make shutdown of the runtime hang until the user presses enter.

For interactive uses, it is recommended to spawn a thread dedicated to user inp…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@acheronfail
Comment options

Answer selected by acheronfail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants