-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
interp: make read
cancellable via Run's ctx
#857
Conversation
theclapp
commented
May 5, 2022
- Add a CancelableReader type, and wrap stdin with it at the top of Runner.Run.
- Also include CancelableReaderTTY which preserves stdin looking like a tty, i.e. [[ -t 0 ]] is still true.
4ef0f77
to
0f22758
Compare
So it turns out that using this CancelableReader triggers these two behaviors of os.Exec:
and 2) from Cmd.Wait:
Which all means that running any external program, such as "date", triggers a read from stdin. Not sure how to get around that just yet. |
Also, the above problem aside, if I/we can get it to work, this feature still needs some unit tests. |
Good observation. I guess this then means that we only avoid spawning our background reader if an interpreted script does not call any program nor does it use stdin itself directly. I'm trying to think how likely that is; I imagine most shell scripts do call external programs. Perhaps it's best to do like |
I've made a lot of progress on this. It got surprisingly complicated, though to be sure a lot of the problem was between my ears. As for Other shells have the interesting property that you can say |
maybe this will help? https://github.com/muesli/cancelreader |
I just gave this a shot with cancelreader and ran into some sort of deadlock in the tests. One problem I noticed is that I'm at a loss. But I'm certainly very interested in this. I too would like some way of essentially sending a shell command |
I guess all I really need is I realized that last night, what I need actually for my own tool is to be able to differentiate a
|
The elivish shell also has support for reading with a timeout, their code might be worth perusing for inspiration, https://github.com/elves/elvish/commits/master/pkg/cli/term/file_reader_unix.go |
I'm happy to defer to someone who has more experience in this area; I've never used Linux's epoll (what cancelreader uses) nor select (what elvish seems to use) so it's not clear to me which is a better approach. I'm not too worried about portability, because some parts of the interpreter like FIFOs or checking for permissions in I admit I'm hoping that we can avoid writing significant amounts of OS-specific code :) |
b081263
to
bb7d2f9
Compare
- Add a CancelableReader type, and wrap stdin with it at the top of Runner.Run. - Also include CancelableReaderTTY which preserves stdin looking like a tty, i.e. [[ -t 0 ]] is still true.
Lots of work on this before realizing my approach was fundamentally flawed, damn it. Committing what I have before refactoring.