-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
No stdin for python calls from bash completion functions #488
Conversation
Prevents usage of stdin by (python) executables that are called during completion generation. This prevents the completion locking up the entire shell when the python script is broken i.e. it enters an interactive mode (REPL) instead of generating the completions, as expected.
Thanks for your interest in argcomplete. Unfortunately I don't think we will be able to accept this pull request. I understand the problem that you're trying to solve, however replacing fd 0 can carry a lot of other side effects which might be more severe and more difficult to solve than simply advising users to not issue blocking reads from stdin before calling I'm going to close this PR for now, but feel free to comment if you want to provide more information on why this might be the right approach, and we can reopen if necessary. |
I'd argue that a program's autocomplete functionality silently breaking is vastly preferable to a user becoming stuck in an invisible program, especially since since this would happen during attempts to tab-complete where a lasting program execution is entirely unexpected. Also, any program executed on a command line can be reasonable expected to have it's sudo sh -c "exit 36" </dev/null >/dev/null 2>/dev/null; echo $? It should also be noted that the
|
OK, those are some good points. Another way of putting it is, stdin being a tty can reasonably be expected to be an indicator for direct interaction with the user, but collecting completions is not direct interaction with the user. It turns out that zsh already shuts off stdin when running completions, so this issue only affects bash. I'm going to think about this a bit more and will likely merge this PR as is.
That's a good point too. I'm thinking maybe argcomplete should spawn background watchdog shellcode for every completion run, to kill the python process after a timeout. |
This could easily be implemented via |
Good suggestion, but I'm not ready to introduce a dependency that's not based on a shell builtin. |
Prevents usage of stdin by (python) executables that are called during completion generation. This prevents the completion locking up the entire shell when the python script is broken i.e. it enters an interactive mode (REPL) instead of generating the completions, as expected.
This lockup can be provoked by having a script marked as compatible, but read
stdin
(& wait) for some reason e.g. due to REPL - I've added a corresponding test.