I've run into a weird problem when starting an interactive python console in the background. After resuming the interpreter from the background, it does not display any of the text I type (i.e. it just shows the >>> prompt, though it will interpret whatever I write. Pressing [enter] created another >>> prompt on the same line).
An easy way to reproduce the problem is just to type:
python &
fg
This problem does does not occur if you start the program in the foreground, put it in the background, and return it to the foreground:
python
[ctrl-z]
bg
fg
If you're wondering why you might want to start an interactive interpreter in the background, consider the following scenario:
I have a simulation that takes a long time to run, but after it's done, I want to interact with the results. Thus, I started the program:
python -i simulation.py &
fg #(after it's finished running)
The easy solution is just to start it in the foreground, move it to the background, and then later bring it to the foreground, but I'm just wondering why this happens.
Consider executing the following commands to force the terminal ECHO mode after you have brought your interpreter into the foreground:
import termios
attr = termios.tcgetattr(1)
attr[3] = attr[3] | termios.ECHO
termios.tcsetattr(1, termios.TCSANOW, attr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With