easy-exit-calls 1.0.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- easy_exit_calls-1.0.0.dev1/LICENSE.md +19 -0
- easy_exit_calls-1.0.0.dev1/PKG-INFO +156 -0
- easy_exit_calls-1.0.0.dev1/README.md +134 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/__init__.py +33 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/classes.py +477 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/classes.py~ +388 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/__init__.py +8 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/__init__.py +9 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/author/__init__.py +10 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/author/contributors/CONTRIB_TEMPLATE.json +52 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/author/contributors/__init__.py +8 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/author/main/__init__.py +8 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/author/software_org/__init__.py +8 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/package/__init__.py +8 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/package/version/__VERSION__ +2 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/common/meta/package/version/__init__.py +13 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/decorator.py +50 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/example_helpers.py +71 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/helpers/__init__.py +8 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/helpers/decorator.py +50 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/helpers/handler_list.py +123 -0
- easy_exit_calls-1.0.0.dev1/easy_exit_calls/log_engine.py +12 -0
- easy_exit_calls-1.0.0.dev1/pyproject.toml +35 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2025 **Inspyre-Softworks**
|
|
2
|
+
|
|
3
|
+
Permission is **hereby granted**, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software (*EasyExitCalls*) and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including **without limitation** the rights
|
|
6
|
+
to *use*, *copy*, *modify*, *merge*, *publish*, *distribute*, **sub***license*, **and**/**or** *sell*
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, **subject to the following conditions**:
|
|
9
|
+
|
|
10
|
+
*The above copyright notice and this permission notice shall be included in **all
|
|
11
|
+
copies** or substantial portions of the Software.*
|
|
12
|
+
|
|
13
|
+
**THE SOFTWARE IS PROVIDED **"*AS IS*"**, WITHOUT WARRANTY OF ANY KIND, *EXPRESS* OR
|
|
14
|
+
*IMPLIED*, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR *ANY CLAIM*, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.**
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: easy-exit-calls
|
|
3
|
+
Version: 1.0.0.dev1
|
|
4
|
+
Summary: A Python library for managing exit handlers with enhanced features like decorators, UUID tracking, and LIFO execution.
|
|
5
|
+
Author: Taylor B.
|
|
6
|
+
Author-email: tayjaybabee@gmail.com
|
|
7
|
+
Requires-Python: >=3.12,<4.0
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Classifier: Topic :: Utilities
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: inspy-logger (==3.2.3)
|
|
18
|
+
Requires-Dist: inspyre-toolbox (>=1.6.0-dev22)
|
|
19
|
+
Requires-Dist: pytz (>=2025.1,<2026.0)
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# easy-exit-calls
|
|
23
|
+
|
|
24
|
+
A Python library for managing exit handlers with enhanced features like decorators, UUID tracking, and LIFO execution.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- **Decorator Support**: Easily register functions as exit handlers using a decorator.
|
|
29
|
+
- **LIFO Execution**: Handlers execute in Last-In-First-Out order by default (configurable).
|
|
30
|
+
- **UUID Tracking**: Each handler is assigned a unique UUID for easy management.
|
|
31
|
+
- **Thread Safety**: Uses threading locks to ensure safe registration/unregistration.
|
|
32
|
+
- **Detailed Logging**: Integrated with a logging engine for debugging and tracking.
|
|
33
|
+
- **Error Handling**: Captures exceptions during exit and logs them with tracebacks.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install easy-exit-calls
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Basic Decorator Usage
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from easy_exit_calls import register_exit_handler
|
|
47
|
+
|
|
48
|
+
@register_exit_handler
|
|
49
|
+
def cleanup():
|
|
50
|
+
print("Cleaning up resources...")
|
|
51
|
+
|
|
52
|
+
# Exiting the program will automatically trigger this handler.
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Decorator with Arguments
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from easy_exit_calls import register_exit_handler
|
|
59
|
+
|
|
60
|
+
@register_exit_handler("arg1", key="value")
|
|
61
|
+
def cleanup_with_args(arg1, key=None):
|
|
62
|
+
print(f"Cleaning up with {arg1} and {key}")
|
|
63
|
+
|
|
64
|
+
# Handler called with provided args/kwargs on exit.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Manual Registration
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from easy_exit_calls import ExitCallHandler
|
|
71
|
+
|
|
72
|
+
def manual_cleanup():
|
|
73
|
+
print("Manual cleanup")
|
|
74
|
+
|
|
75
|
+
ExitCallHandler().register_handler(manual_cleanup)
|
|
76
|
+
|
|
77
|
+
# Exiting the program will manually trigger this handler.
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Unregistering Handlers
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from easy_exit_calls import ExitCallHandler
|
|
84
|
+
|
|
85
|
+
def cleanup():
|
|
86
|
+
print("Cleaning up resources...")
|
|
87
|
+
|
|
88
|
+
handler_uuid = ExitCallHandler().register_handler(cleanup)
|
|
89
|
+
|
|
90
|
+
# Unregister the handler by UUID.
|
|
91
|
+
ExitCallHandler().unregister_by_uuid(handler_uuid)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Execution Order
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from easy_exit_calls import register_exit_handler
|
|
98
|
+
|
|
99
|
+
@register_exit_handler
|
|
100
|
+
def first_handler():
|
|
101
|
+
print("First handler")
|
|
102
|
+
|
|
103
|
+
@register_exit_handler
|
|
104
|
+
def second_handler():
|
|
105
|
+
print("Second handler")
|
|
106
|
+
|
|
107
|
+
# Output on exit:
|
|
108
|
+
# Second handler
|
|
109
|
+
# First handler
|
|
110
|
+
# (LIFO execution order)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API Reference
|
|
114
|
+
|
|
115
|
+
### `ExitCallHandler`
|
|
116
|
+
|
|
117
|
+
Singleton class managing exit handlers.
|
|
118
|
+
|
|
119
|
+
#### Methods:
|
|
120
|
+
|
|
121
|
+
- `register_handler(func: Callable, *args, **kwargs) -> str`:
|
|
122
|
+
Register a new exit handler with optional args/kwargs. Returns the UUID of the handler.<br><br>
|
|
123
|
+
- `unregister_by_uuid(uuid)`:
|
|
124
|
+
Unregister a handler by UUID.<br><br>
|
|
125
|
+
- `unregister_handler(func, *args, **kwargs)`:
|
|
126
|
+
Unregister a handler by function reference and optional args/kwargs.<br><br>
|
|
127
|
+
- `call_handlers()`:
|
|
128
|
+
Manually call all registered handlers.<br><br>
|
|
129
|
+
|
|
130
|
+
### `register_exit_handler`
|
|
131
|
+
|
|
132
|
+
Decorator for registering a function as an exit handler.
|
|
133
|
+
|
|
134
|
+
#### Parameters:
|
|
135
|
+
|
|
136
|
+
- `*handler_args`:
|
|
137
|
+
Optional arguments to pass to the handler function.<br><br>
|
|
138
|
+
- `**handler_kwargs`:
|
|
139
|
+
Optional keyword arguments to pass to the handler function.<br><br>
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## Contributing
|
|
143
|
+
|
|
144
|
+
Contributions are welcome! Here's how you can get started:
|
|
145
|
+
1) Fork the repository.<br><br>
|
|
146
|
+
2) Create a new branch (`git checkout -b feature-branch`).<br><br>
|
|
147
|
+
3) Make your changes.<br><br>
|
|
148
|
+
4) Commit your changes (`git commit -m 'Add feature'`).<br><br>
|
|
149
|
+
5) Push your changes to your fork (`git push origin feature-branch`).<br><br>
|
|
150
|
+
6) Create a pull request.<br><br>
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
This project is released under the [MIT License](LICENSE.md).
|
|
156
|
+
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# easy-exit-calls
|
|
2
|
+
|
|
3
|
+
A Python library for managing exit handlers with enhanced features like decorators, UUID tracking, and LIFO execution.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Decorator Support**: Easily register functions as exit handlers using a decorator.
|
|
8
|
+
- **LIFO Execution**: Handlers execute in Last-In-First-Out order by default (configurable).
|
|
9
|
+
- **UUID Tracking**: Each handler is assigned a unique UUID for easy management.
|
|
10
|
+
- **Thread Safety**: Uses threading locks to ensure safe registration/unregistration.
|
|
11
|
+
- **Detailed Logging**: Integrated with a logging engine for debugging and tracking.
|
|
12
|
+
- **Error Handling**: Captures exceptions during exit and logs them with tracebacks.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install easy-exit-calls
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Basic Decorator Usage
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from easy_exit_calls import register_exit_handler
|
|
26
|
+
|
|
27
|
+
@register_exit_handler
|
|
28
|
+
def cleanup():
|
|
29
|
+
print("Cleaning up resources...")
|
|
30
|
+
|
|
31
|
+
# Exiting the program will automatically trigger this handler.
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Decorator with Arguments
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from easy_exit_calls import register_exit_handler
|
|
38
|
+
|
|
39
|
+
@register_exit_handler("arg1", key="value")
|
|
40
|
+
def cleanup_with_args(arg1, key=None):
|
|
41
|
+
print(f"Cleaning up with {arg1} and {key}")
|
|
42
|
+
|
|
43
|
+
# Handler called with provided args/kwargs on exit.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Manual Registration
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from easy_exit_calls import ExitCallHandler
|
|
50
|
+
|
|
51
|
+
def manual_cleanup():
|
|
52
|
+
print("Manual cleanup")
|
|
53
|
+
|
|
54
|
+
ExitCallHandler().register_handler(manual_cleanup)
|
|
55
|
+
|
|
56
|
+
# Exiting the program will manually trigger this handler.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Unregistering Handlers
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from easy_exit_calls import ExitCallHandler
|
|
63
|
+
|
|
64
|
+
def cleanup():
|
|
65
|
+
print("Cleaning up resources...")
|
|
66
|
+
|
|
67
|
+
handler_uuid = ExitCallHandler().register_handler(cleanup)
|
|
68
|
+
|
|
69
|
+
# Unregister the handler by UUID.
|
|
70
|
+
ExitCallHandler().unregister_by_uuid(handler_uuid)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Execution Order
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from easy_exit_calls import register_exit_handler
|
|
77
|
+
|
|
78
|
+
@register_exit_handler
|
|
79
|
+
def first_handler():
|
|
80
|
+
print("First handler")
|
|
81
|
+
|
|
82
|
+
@register_exit_handler
|
|
83
|
+
def second_handler():
|
|
84
|
+
print("Second handler")
|
|
85
|
+
|
|
86
|
+
# Output on exit:
|
|
87
|
+
# Second handler
|
|
88
|
+
# First handler
|
|
89
|
+
# (LIFO execution order)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API Reference
|
|
93
|
+
|
|
94
|
+
### `ExitCallHandler`
|
|
95
|
+
|
|
96
|
+
Singleton class managing exit handlers.
|
|
97
|
+
|
|
98
|
+
#### Methods:
|
|
99
|
+
|
|
100
|
+
- `register_handler(func: Callable, *args, **kwargs) -> str`:
|
|
101
|
+
Register a new exit handler with optional args/kwargs. Returns the UUID of the handler.<br><br>
|
|
102
|
+
- `unregister_by_uuid(uuid)`:
|
|
103
|
+
Unregister a handler by UUID.<br><br>
|
|
104
|
+
- `unregister_handler(func, *args, **kwargs)`:
|
|
105
|
+
Unregister a handler by function reference and optional args/kwargs.<br><br>
|
|
106
|
+
- `call_handlers()`:
|
|
107
|
+
Manually call all registered handlers.<br><br>
|
|
108
|
+
|
|
109
|
+
### `register_exit_handler`
|
|
110
|
+
|
|
111
|
+
Decorator for registering a function as an exit handler.
|
|
112
|
+
|
|
113
|
+
#### Parameters:
|
|
114
|
+
|
|
115
|
+
- `*handler_args`:
|
|
116
|
+
Optional arguments to pass to the handler function.<br><br>
|
|
117
|
+
- `**handler_kwargs`:
|
|
118
|
+
Optional keyword arguments to pass to the handler function.<br><br>
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Contributing
|
|
122
|
+
|
|
123
|
+
Contributions are welcome! Here's how you can get started:
|
|
124
|
+
1) Fork the repository.<br><br>
|
|
125
|
+
2) Create a new branch (`git checkout -b feature-branch`).<br><br>
|
|
126
|
+
3) Make your changes.<br><br>
|
|
127
|
+
4) Commit your changes (`git commit -m 'Add feature'`).<br><br>
|
|
128
|
+
5) Push your changes to your fork (`git push origin feature-branch`).<br><br>
|
|
129
|
+
6) Create a pull request.<br><br>
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
This project is released under the [MIT License](LICENSE.md).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides a simple way to register exit handlers for your Python applications.
|
|
3
|
+
|
|
4
|
+
The main class is ExitCallHandler, which is used to register and manage exit handlers.
|
|
5
|
+
|
|
6
|
+
Included is a decorator, register_exit_handler, which can be used to register an exit handler for a function. This is a
|
|
7
|
+
convenient way to register exit handlers for functions.
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
>>> from easy_exit_calls import register_exit_handler, ExitCallHandler
|
|
11
|
+
>>>
|
|
12
|
+
>>> @register_exit_handler()
|
|
13
|
+
... def my_exit_handler():
|
|
14
|
+
... print("Exiting...")
|
|
15
|
+
...
|
|
16
|
+
>>> # Create an instance of ExitCallHandler
|
|
17
|
+
>>> eh = ExitCallHandler()
|
|
18
|
+
>>>
|
|
19
|
+
>>> # Register an exit handler
|
|
20
|
+
>>> eh.register_handler(my_exit_handler)
|
|
21
|
+
>>>
|
|
22
|
+
>>> # Call the exit handlers
|
|
23
|
+
>>> eh.call_handlers()
|
|
24
|
+
Exiting...
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from easy_exit_calls.classes import ExitCallHandler
|
|
28
|
+
from easy_exit_calls.decorator import register_exit_handler
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
'ExitCallHandler',
|
|
32
|
+
'register_exit_handler',
|
|
33
|
+
]
|