1
python腳本僅爲自刷新的npyscreen(curses)腳本每1分鐘顯示一次狀態。用戶點擊ctrl-c後,應該註銷。登錄到Raspbian +在python腳本結束時運行python腳本+註銷
python腳本僅爲自刷新的npyscreen(curses)腳本每1分鐘顯示一次狀態。用戶點擊ctrl-c後,應該註銷。登錄到Raspbian +在python腳本結束時運行python腳本+註銷
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()
你如何登錄?直接在Pi或通過_ssh_? – Finwood