Handle graceful process termination
Project description
Safe Exit is a Python package that provides functionality to handle graceful process termination. The package allows users to register functions that will be called when the program exits.
Different between atexit
Python has standard module atexit do similar thing, but atexit can’t handle when program is killed by a signal not handled by Python.
Python only handle SIGINT signal, don’t handle SIGTERM, SIGQUIT, SIGHUP signals. On Windows, program will also killed by SIGBREAK and CTRL_CLOSE_EVENT.
safe-exit can handle all this signals:
On posix system: SIGINT, SIGTERM, SIGQUIT, SIGHUP
On windows: SIGINT, SIGTERM, SIGBREAK, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT
Windows also has CTRL_C_EVENT and CTRL_BREAK_EVENT which will translate to SIGINT, SIGBREAK signal by python. On windows, SIGTERM are implemented just for the current process, there is no way to send SIGTERM to other process.
Installation
To install Safe Exit, simply run:
pip install safe-exit
Usage
Just register clean up function like atexit:
import safe_exit
def cleanup_function():
# Perform cleanup tasks
safe_exit.register(cleanup_function)
register function can also used as function annotation
@safe_exit.register
def cleanup_function():
# Perform cleanup tasks
Nicely kill a process, giving it a chance to clean up:
process_id = ...
safe_exit.nice_kill(process_id)
Contributing
Contributions to Safe Exit are welcome! Please read the contributing guidelines before submitting a pull request or reporting an issue.
License
Safe Exit is released under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for safe_exit-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfed2f274ac00d2f23dfe23aaef78e099e0da3777cab226f247da4f19f4e66b4 |
|
MD5 | ce0f434e22d0d5ce5afb14f6a6490462 |
|
BLAKE2b-256 | 50c4a1290816ac63905533dabb181443401a8396fc275c92c26f495c2d2e778f |