Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ra101/grim_reapers.py
A collection of Context-Decorators to mange the termination of python processes.
https://github.com/ra101/grim_reapers.py
Last synced: 3 days ago
JSON representation
A collection of Context-Decorators to mange the termination of python processes.
- Host: GitHub
- URL: https://github.com/ra101/grim_reapers.py
- Owner: ra101
- License: gpl-2.0
- Created: 2024-08-22T15:18:13.000Z (5 months ago)
- Default Branch: core
- Last Pushed: 2024-12-17T19:08:23.000Z (22 days ago)
- Last Synced: 2024-12-17T20:19:01.722Z (21 days ago)
- Language: Python
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Grim Reapers
A collection of Context-Decorators to mange the termination of python processes.### Installation
```bash
pip install git+https://github.com/ra101/grim_reapers.py.git# Install with other ratools.py utils.
pip install git+https://github.com/ra101/ratools.py.git
```### Usage
Assume the following function needs to gracefully terminated
```python
import timeDRIVER_RUN = True
def driver_function():
global DRIVER_RUN
while DRIVER_RUN:
time.sleep(0.2)
```and assume the following function is for terminating above function.
```python
def stop_driver_function():
global DRIVER_RUN
DRIVER_RUN = False
```**We will use the following methods for calling reapers:**
```python
# Decorator
@reaper
def _driver_function()
return driver_function()# Context Manager
with reaper:
driver_function()# Context Manager (Multiple Reapers)
from contextlib import ExitStackreaper = [...]
with ExitStack() as stack:
for reaper in reapers:
stack.enter_context(reaper)driver_function()
```
β#### πβ οΈ Signal Reaper
Terminate the process once the interrupt signal is received on its PID.
```python
from grim_reapers import SignalReaperreaper = SignalReaper(
exit_callback=stop_driver_function,
# sig_enums=(signal.SIGINT, signal.SIGTERM), logger=sys.stdout.write,
)
```β
#### πβ οΈ Time Reaper
Terminate the process after certain time period is over.
```python
from grim_reapers import TimeReaperreaper = SignalReaper(
exit_callback=stop_driver_function,
# stop_time=10, logger=sys.stdout.write,
)
```β
#### πΈοΈβ οΈ Webhook Reaper
Terminate the process once a webhook is accessed.
```python
from grim_reapers import WebhookReaperreaper = WebhookReaper(
exit_callback=stop_driver_function,
# port=8342, logger=sys.stdout.write,
)
```β
#### π«β οΈ Beat Reaper
Terminate the process once the beat_function stops returning true.
```python
from grim_reapers import WebhookReaperreaper = WebhookReaper(
exit_callback=stop_driver_function,
beat_function=lambda check_beat: _return_true_false_or_exception(),
# beat_interval=2, logger=sys.stdout.write,
)
```