'Call a function when the Python process gets terminated using Task Manager in Python
I'm working on a GUI application which lets you configure some options. When you close the application using the buttons on GUI, the program saves the configuration to a database file.
I'm using the atexit module for this task:
import atexit
def on_exit():
print("Exiting...")
# Save to a database
atexit.register(on_exit)
However, the function doesn't get called when I terminate the Python process using Task Manager. I don't clearly know how Task Manager terminates processes, but is it possible to do the same thing for terminations made with Task Manager in Windows?
Solution 1:[1]
I don't know how Task Manager terminates processes. It's likely to send one of two signals - either SIGTERM or SIGKILL.
If it's the former then you can set a handler for that. See signal
If it's the latter, then you can't do anything about it
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Albert Winestein |
