How to capture a command prompt window close event in python
Question: I want to capture command window close event from Python.  
In other words, when the user tries to close the command prompt window, script
should detect it and display a message like `Do you really want to exit -
Yes/No`

Any suggestions about how to implement this? Please help me in doing this.


Answer: 
    def on_exit(sig, func=None):
        print "exit handler"
    

There should be two way to do that, if you install pywin32 package, you can :

    
    
    import win32api
    win32api.SetConsoleCtrlHandler(func, True)
    

Or, using python internal "signal" library, if you are using under *nix
system:

    
    
    import signal
    signal.signal(signal.SIGTERM, func)
    

