1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# -*- coding: utf-8 -*- ## Copyright 2019 Trevor van Hoof and Jan Pijpers. ## Licensed under the Apache License, Version 2.0 ## Downloaded from https://janpijpers.com or https://gumroad.com/janpijpers ## See the license file attached or on https://www.janpijpers.com/script-licenses/ ''' Name: functionOnExit Description: Run a function on closing a console window. windows only i guess. ''' import atexit import time def _run_function_on_exit(): ''' Function that will be called when the program actually exits. This is also called on a ctrl-c event. alt-f4 or x button will skip the raw input, but the function will still be called. ''' print "You are exiting, press enter to exit" raw_input() if __name__ == "__main__": ## Register the function to be run when the system exits. atexit.register( _run_function_on_exit ) for x in range(5,0,-1): print "Closing in:", x time.sleep(1) |