easy-exit-calls
A Python library for managing exit handlers with enhanced features like decorators, UUID tracking, and LIFO execution.
Features
- Decorator Support: Easily register functions as exit handlers using a decorator.
- LIFO Execution: Handlers execute in Last-In-First-Out order by default (configurable).
- UUID Tracking: Each handler is assigned a unique UUID for easy management.
- Thread Safety: Uses threading locks to ensure safe registration/unregistration.
- Detailed Logging: Integrated with a logging engine for debugging and tracking.
- Error Handling: Captures exceptions during exit and logs them with tracebacks.
Installation
This project requires Python 3.12 or later.
pip install easy-exit-calls
Usage
Basic Decorator Usage
from easy_exit_calls import register_exit_handler
@register_exit_handler
def cleanup():
print("Cleaning up resources...")
# Exiting the program will automatically trigger this handler.
Decorator with Arguments
from easy_exit_calls import register_exit_handler
@register_exit_handler("arg1", key="value")
def cleanup_with_args(arg1, key=None):
print(f"Cleaning up with {arg1} and {key}")
# Handler called with provided args/kwargs on exit.
Manual Registration
from easy_exit_calls import ExitCallHandler
def manual_cleanup():
print("Manual cleanup")
ExitCallHandler().register_handler(manual_cleanup)
# Exiting the program will manually trigger this handler.
Unregistering Handlers
from easy_exit_calls import ExitCallHandler
def cleanup():
print("Cleaning up resources...")
handler_uuid = ExitCallHandler().register_handler(cleanup)
# Unregister the handler by UUID.
ExitCallHandler().unregister_by_uuid(handler_uuid)
Execution Order
from easy_exit_calls import register_exit_handler
@register_exit_handler
def first_handler():
print("First handler")
@register_exit_handler
def second_handler():
print("Second handler")
# Output on exit:
# Second handler
# First handler
# (LIFO execution order)
API Reference
ExitCallHandler
Singleton class managing exit handlers.
Methods:
register_handler(func: Callable, *args, **kwargs) -> str: Register a new exit handler with optional args/kwargs. Returns the UUID of the handler.unregister_by_uuid(uuid): Unregister a handler by UUID.unregister_handler(func, *args, **kwargs): Unregister a handler by function reference and optional args/kwargs.call_handlers(): Manually call all registered handlers.
register_exit_handler
Decorator for registering a function as an exit handler.
Parameters:
*handler_args: Optional arguments to pass to the handler function.**handler_kwargs: Optional keyword arguments to pass to the handler function.
Running Tests
Run the test suite with pytest from the project root:
pytest
Contributing
Contributions are welcome! Here's how you can get started:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes.
- Commit your changes (
git commit -m 'Add feature'). - Push your changes to your fork (
git push origin feature-branch). - Create a pull request.
License
This project is released under the MIT License.
Metadata
Release files for easy-exit-calls 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easy_exit_calls-1.0.0.tar.gz | 9.8 kB | Without provenance | Details for easy_exit_calls-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easy_exit_calls-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for easy_exit_calls-1.0.0-py3-none-any.whl |
Total release size: 24.8 kB
Release files / easy_exit_calls-1.0.0.tar.gz
| Download URL | easy_exit_calls-1.0.0.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98be0323726a37b2481877a8a0c60a9e555f4495eeccbcade0953c504c0313e2
|
|
BLAKE2b-256 checksum How to use checksums |
0cb6dc82ba808e714e2721fb157e3552b58e6c4ffa9dad94a2c781a6de07f400
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.14.5 Windows/11
|
Release files / easy_exit_calls-1.0.0-py3-none-any.whl
| Download URL | easy_exit_calls-1.0.0-py3-none-any.whl |
|---|---|
| Size | 15.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c3336d8124cd8ae480e0b4f3e8debd72c40e7d46c556a58185fa64d16442bae
|
|
BLAKE2b-256 checksum How to use checksums |
c140248643cb3c53b06043f0265b8a605316c57d74804f87a97d97c989287059
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.14.5 Windows/11
|
Security for easy-exit-calls 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.