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

Suspending user input request from the .bashrc #111

Closed
cailloumax opened this issue Apr 15, 2021 · 2 comments
Closed

Suspending user input request from the .bashrc #111

cailloumax opened this issue Apr 15, 2021 · 2 comments

Comments

@cailloumax
Copy link

Issue

I ask for user input in my .bashrc, because I need to have different environnement variables in different context. It cause the bash_kernel to repeatidly crash, due to timeout like in issue #71.

My solution

Based on @takluyver answer to the issue I modified - pexpect/pexpect#459 the following way:

# Placing an environnement variable to avoid the .bashrc asking for user input
export no_user_input="True" 
# Different platforms have different names for the systemwide bashrc
if [[ -f /etc/bashrc ]]; then
  source /etc/bashrc
fi
if [[ -f /etc/bash.bashrc ]]; then
  source /etc/bash.bashrc
fi
if [[ -f ~/.bashrc ]]; then
  source ~/.bashrc
fi

# Reset PS1 so pexpect can find it
PS1="$"

# Unset PROMPT_COMMAND, so that it can't change PS1 to something unexpected.
unset PROMPT_COMMAND

I set the no_user_input environnement variable and then detect this variable in my .bashrc to supress the query for user input

Cleaner solution

Is there a best solution ? Does pexpect already set a variable I may use for my test ?

@takluyver
Copy link
Owner

I can't think of anything already set that you could detect for this. Part of the what Pexpect does is tricking programs into using their 'interactive mode', either for testing or for automating awkward programs.

I'd be open to bash_kernel setting something like JUPYTER_BASH_KERNEL=1 so that things run from bash can detect it.

(I've also wanted some standard environment variable to tell all programs not to wait for user input, e.g. when running apt-get install from a dockerfile. But I don't know of anything like that.)

@kdm9
Copy link
Collaborator

kdm9 commented May 8, 2024

closing, will implement an env var as part of #145

@kdm9 kdm9 closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants