Reputation: 29
For instance, let the program write down a log file before I manually stop it.
Upvotes: 1
Views: 258
Reputation: 2045
You can use atexit
module: https://docs.python.org/3.5/library/atexit.html
Example:
import atexit
import time
def exit_hook():
print("Exiting!")
atexit.register(exit_hook)
while True:
print("looping...")
time.sleep(1)
Upvotes: 4