My bash terminal in Ubuntu gets messed up after running a Python script. I have no clue why but after that, I can't use it again and need to close the shell and open a new one.

I am attaching a picture for you to see. Maybe someone can point out what could be a reason for this to happen.

enter image description here

1 Answer 1


This usually happens when the script uses some commands to change terminal settings and fails to reset them back to their default before it ends.

For instance, you can simulate a situation such as this with this command:

stty -echo

(I expect it will look like what you're experimenting.)

You can typically get back to "normal" with the reset command, so try pressing Ctrl+C or Return to make sure you're at the start of a new prompt, then type "reset" (you won't see anything) and Return and things might get back to normal:


It's hard to tell what checkpoint_ps.py is doing that's leaving the terminal in a weird state... Though disabling terminal "echo" might be that... It's a common thing to do while asking for a password (so the password doesn't show up.) It looks from the output like "sudo" is getting involved, so I wouldn't expect checkpoint_ps.py would be messing with the terminal itself... But who knows, it's possible. If you find something in there that might be related to that, maybe ask a separate question about it so we can help you figure that out too.

  • 3
    Here, it's more the effect of stty -onlcr. stty -echo just disables the echo of what you type. See also stty sane to restore sane values of tty settings Apr 5, 2018 at 9:22
  • To be honest @StéphaneChazelas it might be a combination of both because I can't see what I am typing. Maybe I should give it a try and see if i can do reset. Well I do have access to the source code so I know that the program is making multiple Popen calls. Some of them are executed by invoking a shell first because shell=True. The problem started recently when I added some more calls. So something must be going wrong with one call. I'll try reset and stty sane. Could this be that one process did not end correctly? Apr 6, 2018 at 6:06
  • Yes, it's quite possible that one process didn't end correctly and caused this. Processes are supposed/expected to "revert" the changes to the terminal after they're done with it, but if they are forcefully terminated, or not completely prepared for that, or buggy, then you might end up in that state...
    – filbranden
    Apr 6, 2018 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .