Receive the kill signal from the operating system and gracefully wait for the worker thread to end.
Project description
graceful-sigterm
Receive the kill signal from the operating system and gracefully wait for the worker thread to end.
Note: The package name is graceful-sigterm
but the module name is sigterm
for short.
Install
pip install graceful-sigterm
Usage Example 1
example1.py
import time
import signal
import sigterm
def worker():
print("Press Ctrl+C, and wait 5 seconds to stop...")
while not sigterm.is_stopped():
print(".", end="", flush=True)
sigterm.wait_until_stop(timeout=1)
print("")
for i in range(5):
print("x", end="", flush=True)
time.sleep(1)
def main():
sigterm.setup()
sigterm.setup(signal.SIGINT)
sigterm.register_worker(worker)
sigterm.execute()
if __name__ == "__main__":
main()
output
test@test-Pro sigterm % python example1.py
Press Ctrl+C, and wait 5 seconds to stop...
....^C
xxxxx%
Releases
v0.1.0
- First realse.
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
graceful-sigterm-0.1.0.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for graceful_sigterm-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2d89ec810ecb87ac530af6df77eb97262f33b6b0d74219b04dc4152053ccd96 |
|
MD5 | 5f5dc48cff7571a48d812c4695575c1f |
|
BLAKE2b-256 | d76f554df22c3eb694966a3bc40fe88479a61f72cef20d6bac3bee4b5a2b9b8e |