python脚本只是 一个自刷新的npyscreen(curses)脚本,每1分钟显示一次状态。用户点击 ctrl-c 后,应该注销。
答案 0 :(得分:2)
来自this answer:
import os
import subprocess
def logoff():
ppid = os.environ['PPID']
subprocess.call(["kill", "-HUP", ppid])
您必须抓住KeyboardInterrupt
例外:
def main():
try:
display_status()
except KeyboardInterrupt:
logoff()
def display_status():
pass # your code goes here
if __name__ == '__main__':
main()
答案 1 :(得分:0)
如果您使用远程连接登录,则应该能够将ssh key logins设置为Pi,并在您将要登录的用户帐户的主目录下设置为,只需修改~/.bash_profile
。
~/.bash_profile
,并根据规范配置bash。在此,您可以加载别名,函数并运行任何启动脚本。
至于退出^C
,虽然我从未亲自完成,但我建议导入子流程并在键盘中断上设置错误处理程序以将退出传递回Bash。