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.
def inform():
    print('You close programm with Ctrl-C.')

# Push goodbuy function to stack.
def goodbuy():

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

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

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Files for pycloser, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size pycloser-0.2.tar.gz (1.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page