Skip to main content

Сlean exit for Python scripts after Ctrl-C.

Project description

Сlean exit for Python scripts after Ctrl-C. Inspired by xlab’s Closer for Go (Golang). # Usage

from pycloser import defer, listen, close

# Push inform function to stack.
@defer
def inform():
    print('You close programm with Ctrl-C.')

# Push goodbuy function to stack.
@defer
def goodbuy():
    print('Goodbuy!')

# Listening SIGINT, SIGTERM and SIGHUP OS signals.
# When it sended, listen() pop deferred functions from stack
# and call its one after the other.
listen()

# Main programm loop
for x in range(1, 10):
    print("{0}: {1}".format(x, input(">> ")))

# Pop deferred functions from stack and call its, if signal was not sended.
close()

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycloser-0.2.tar.gz (1.7 kB view details)

Uploaded Source

File details

Details for the file pycloser-0.2.tar.gz.

File metadata

  • Download URL: pycloser-0.2.tar.gz
  • Upload date:
  • Size: 1.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pycloser-0.2.tar.gz
Algorithm Hash digest
SHA256 21371ae1c1a8f498e7a0240049c0d0d9e358ff9b4c4b6a28f835efebd24674d7
MD5 3972ac44dab349ad7dad7cba318754f3
BLAKE2b-256 d115b49e401729502ea67d03c21a7c4580cd7495015854582984efce00db006e

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