How to Exit Linux terminal using Python script?
SIGHUP
(hang up) will tell the terminal to exit. The terminal should be your script's parent process, so
import os
import signal
os.kill(os.getppid(), signal.SIGHUP)
Instead of running the command from the shell with just the command name, run it with exec
which will cause the shell to replace itself with the program. Then when the program exits the terminal window will close as well.
I.e. instead of
$ python ./my_script.py
run:
$ exec python ./my_script.py