Skip to main content
Help us improve Python packaging – donate today!

С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()

Release history Release notifications

This version
History Node

0.2

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
pycloser-0.2.tar.gz (1.7 kB) Copy SHA256 hash SHA256 Source None Aug 5, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page