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-Pro sigterm % python example1.py
Press Ctrl+C, and wait 5 seconds to stop...
....^C
xxxxx%      

Releases

v0.1.0

  • First realse.

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graceful_sigterm-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file graceful-sigterm-0.1.0.tar.gz.

File metadata

  • Download URL: graceful-sigterm-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for graceful-sigterm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a78a2675609ccee1b503b5f49237bc39875fea48b776f1eea9081a386175de4e
MD5 d741eb0e6e0054d5ed14bf29fe65b10d
BLAKE2b-256 06b318a50330678fc893ddaaf3fa3a4003a8a4c2696f30aad4ccd08c35fce06c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graceful_sigterm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2d89ec810ecb87ac530af6df77eb97262f33b6b0d74219b04dc4152053ccd96
MD5 5f5dc48cff7571a48d812c4695575c1f
BLAKE2b-256 d76f554df22c3eb694966a3bc40fe88479a61f72cef20d6bac3bee4b5a2b9b8e

See more details on using hashes here.

Supported by

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