I understand that using import os os._exit(0)
will pause the code, but I would like to kill terminal completely, as if I were clicking on the button shaped like a trash can.
Is there any way to do this so I can put it inside my python code?
CodePudding user response:
It's hacky and won't work inside a Python subprocess, but it works in a basic sense:
import os
ppid = os.getppid()
os.system("taskkill /f /pid " str(ppid))
CodePudding user response:
# This is another way of doing it more pythonic way. Step 1: import os and signal. Step 2: call os.kill with parameters parent process id and SIGTERM (i.e. Signal to terminate the process)
import os
import signal
os.kill(os.getppid(), signal.SIGTERM)