Skip to main content

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 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

  • 更友好的提示信息。

Project details


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.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

graceful_sigterm-0.1.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file graceful_sigterm-0.1.3.tar.gz.

File metadata

  • Download URL: graceful_sigterm-0.1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for graceful_sigterm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b41ea7b6d979f7599d5e21ae6b845374406af4cda95f29769b4bd2c7a1aaab1b
MD5 d719fc53c30ed577fa65d8865660545d
BLAKE2b-256 18f69d2c26aec0bd25c014ad26e75d266c2c0a87a16cb623cc77c46bcb8409f0

See more details on using hashes here.

File details

Details for the file graceful_sigterm-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for graceful_sigterm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 40c885878431fb99ff6e191ec427e3cd81752481027ebf0974c41954920ea1ce
MD5 bb7370e42400da8355a4a70b29226dff
BLAKE2b-256 41aeae5b13bc93b3d688b48929166621875f34b4169e33933d85b51ac573ad19

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page