gpt4 book ai didi

python - 登录 Raspbian + 运行 python 脚本 + python 脚本结束时注销

转载 作者:行者123 更新时间:2023-12-01 04:30:41 25 4
gpt4 key购买 nike

Python 脚本只是一个自刷新 npyscreen(curses)脚本,每 1 分钟显示一次状态。用户点击ctrl-c后,它应该注销。

最佳答案

来自this answer :

import os
import subprocess

def logoff():
ppid = os.environ['PPID']
subprocess.call(["kill", "-HUP", ppid])

您必须捕获 KeyboardInterrupt异常(exception):

def main():
try:
display_status()
except KeyboardInterrupt:
logoff()


def display_status():
pass # your code goes here

if __name__ == '__main__':
main()

关于python - 登录 Raspbian + 运行 python 脚本 + python 脚本结束时注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32431592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com