-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 timeout to Base.prompt #39027
base: master
Are you sure you want to change the base?
Add timeout to Base.prompt #39027
Conversation
2559a32
to
782c1ac
Compare
I seem to be doing something illegal in the tests here by using I just want to simulate
doesn't work because
doesn't seem to work in the tests, perhaps because Is there another way to simulate an open stdin with no data? |
|
I see. So implementing this timeout would need to be done at a lower |
I thought about sending something to stdin to unblock readline. Is that possible? This approach doesn't work
|
Another approach that doesn't work. Fake closing the stdin. begin
stat_before = stdin.status
Timer((t)->stdin.status = Base.StatusClosed, 4)
try
line = readline(stdin)
finally
stdin.status = stat_before
end
end |
Oh yeah, I forget there was a fake StatusEOF that can be triggered manually. It should be okay to grab the correct locks and set that:
It is likely not well-tested or supported, since we don't implement half-open streams properly, but it does exist already at least. |
Nice! This works
|
90a2bed
to
94aa3c6
Compare
0af4206
to
a23470c
Compare
This comment has been minimized.
This comment has been minimized.
827f32b
to
64b4b20
Compare
@vtjnash Tests are finally passing. I took the lead from what other stdin tests do. I introduced this as a second method to maintain the non-timeout method for IJulia etc. |
Good to go @vtjnash ? |
Bump (this just came up on slack as a wanted feature) |
base/util.jl
Outdated
For instance, the user enters a value and hits `return`: | ||
```julia | ||
julia> Base.prompt("Proceed? y/n"; default="n", timeout=5) | ||
Proceed? y/n [n] timeout 5 seconds: y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "timeout 5 seconds" part looks a bit strange or misplaced. Does it have to be displayed to the user at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems useful to have but probably a clearer wording like "Proceed? y/n. Default value [n] will be used in 5 seconds: y" would be better?
This looks like a good feature but I'm iffy on the implementation. It would be much better not to define this only for LibuvStream, since if input is redirected you'll get a MethodError. It's also not great to poke at the LibuvStream internals. So I think this should wait until we have a reliable way to implement it. |
Good point from @vtjnash : arguably the timeout should be canceled as soon as you start typing. |
In that case, it's possible this can only really work for a TTY, and for other IO streams just ignore the timeout? |
6278e36
to
4a215d4
Compare
I've updated this with a focus on getting it to behave how it should Except for the FIXME which I couldn't figure out, I think it's quite nice. However the implementation needs review for properness. Screen.Recording.2024-10-31.at.3.47.03.PM.mov |
Adds an optional timeout to
prompt
to return the default after a given number of secondsSee #39027 (comment)