我的 friend 在 macOS 环境中,他想在他的 python 脚本末尾调用 os.system('exit')
来关闭终端。它没有。这并不让我感到惊讶,但我想知道 在进行此调用时 python 脚本和终端之间到底发生了什么。
在我的心理模拟中,终端应该告诉您仍有正在运行的作业,但这也没有发生。
作为附带问题:当进程调用它时,一些不太常见的终端会关闭吗?
最佳答案
阅读帮助:
Execute the command (a string) in a subshell.
子 shell 启动,exit
在该子 shell 中运行。
要退出封闭终端,您必须杀死父终端。一种方法是:
os.system("kill -9 %d"%(os.getppid())
关于python - os.system ('exit' ) 在 python 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7368523/