如何使用Python脚本退出Linux终端? [英] How to Exit Linux terminal using Python script?

查看:383
本文介绍了如何使用Python脚本退出Linux终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import sys

def end():
    foo=raw_input()
    sys.exit()

print 'Press enter to Exit python and Terminal'

end()

运行程序时,我们应该能够退出Python解释器和终端本身. 但它只会退出python解释器,而不会退出终端.

When we run the program, we should able to exit the Python Interpreter and Terminal itself. But it only exits python interpreter, not the terminal.

提前谢谢.

推荐答案

SIGHUP(挂断)将告诉终端退出.终端应该是您脚本的父进程,所以

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)

这篇关于如何使用Python脚本退出Linux终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆