Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
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.
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.

Release History

This version
History Node


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
(1.7 kB) Copy SHA256 Hash SHA256
Source None Aug 5, 2015

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting