0

I'm running into an issue with the input() function in python 3.7.9. Under certain conditions, all keyboard input is no longer being reflected on screen and [ENTER/RETURN] key no longer submits the user input. Occasionally, it will finally submit, but the command would look like what is below. When the issue occurs, it will only reflect maybe 1 or 2 key presses on screen and stop updating. Most of the time no keyboard presses are recognized:

# User typed "1" and pressed ENTER/RETURN. Nothing happened, so they spammed ENTER print(cmd) > 1\r\r\r\r\r\r\r 

Other Example When trying to quit

print(cmd) > q\r\r\r\r\r\r\r1231231231312\r\r\r 

Which causes issues, because the user is then unable to quit this interactive cli without ctrl+c. Killing the entire program. This issue only occurs when running the interactive UI as apart of the full program package, outlined below. Running standalone, program works flawlessly.


Basic program layout and definitions:

Program A - Shell wrapper. Triggers execution of hundreds of other shell scripts. Calls Program B in main thread to monitor shell script output and logs.

Program B - Python Interactive CLI UI that shows tabled view of running scripts, logs, failure state. Uses single key presses to control. Ex: Pressing 'h' will open help menu. Pressing 'down arrow' will select a different listed log file.

# Call using subprocess.run() IFS= read -r -t -5 -n 1 -s key echo $key 

Program C (Problem Child) - Interactive CLI that accepts command strings as input. Ex: Typing command "save 1" will save current state to memory with name "1". Uses built in function input().

while True: user_input = input("Command: ") if user_input == "my_command": // Do Stuff ... 

Running Program C directly, python3 programC.py works without issue. (User presses V to open Program C from program B)

Running Program C from Program B, python3 programB.py arg1 arg2 arg3 works without issue

Running Program C from Program B from Program A in review mode (review older executions) ./programA -review /log/dir/5, works without issue

Running Program C from Program B from Program A in execution mode (executing hundreds of shell scripts and monitoring output) causing issue with python3 input() command hanging and not returning.

Running Program A w/ 100 shell scripts in background. Then running second Program A in review mode on current execution, does not cause this issue.


Additional info: using following tput commands cmcup, rmcup, cvvis, civis, clear to control terminal screen.

2
  • 1
    Something in your program put the terminal in raw mode before calling input(). Commented Aug 8, 2024 at 19:53
  • Try to create a minimal reproducible example... Commented Aug 9, 2024 at 9:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.