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

  • 修正主线程中长时间待子线程结束导致无法拦截信号的问题。

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: graceful_sigterm-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 97e0db75d0d8042949d71879efb31e340b7ab789cd1be6554d0904c00d8424d2
MD5 ebdf034dbbdaedf402fe3b5581a7097a
BLAKE2b-256 aa50c960ae4e2876cf97c31f83a753dd1bcd1b9919b511f52c7606aa703dfed1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graceful_sigterm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e90102f7a7e738cf1964cb3b78e1fdc0ded4f8b9a152c0e0ff48cd153bbbffd1
MD5 74ee4425169b752364699b8b58854b08
BLAKE2b-256 0aa174abb03f217fd8dfc4597c4824f0abd182aa199a9a7205e39df84ca4ce0d

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