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 sigterm % python example1.py
Press Ctrl+C, and wait 5 seconds to stop...
....^C
xxxxx%
Releases
0.1.0
- 版本首发。
0.1.1
- 文档修改。
0.1.2
- 修正主线程中长时间待子线程结束导致无法拦截信号的问题。
0.1.3
- 更友好的提示信息。
Release files for graceful-sigterm 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| graceful_sigterm-0.1.3.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| graceful_sigterm-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.8 kB
Release files / graceful_sigterm-0.1.3.tar.gz
| Download URL | graceful_sigterm-0.1.3.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b41ea7b6d979f7599d5e21ae6b845374406af4cda95f29769b4bd2c7a1aaab1b
|
|
BLAKE2b-256 checksum How to use checksums |
18f69d2c26aec0bd25c014ad26e75d266c2c0a87a16cb623cc77c46bcb8409f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / graceful_sigterm-0.1.3-py3-none-any.whl
| Download URL | graceful_sigterm-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
40c885878431fb99ff6e191ec427e3cd81752481027ebf0974c41954920ea1ce
|
|
BLAKE2b-256 checksum How to use checksums |
41aeae5b13bc93b3d688b48929166621875f34b4169e33933d85b51ac573ad19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|