2015-09-07 138 views

回答

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()