Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Timeout library for generic interruption of main thread by an exception after a configurable duration

Project description

Timeout library for generic interruption of main thread by an exception after a configurable duration.

Use case

Set a timeout (seconds) upon expiration of which an exception is raised:

from timeout import timeout

…as a context manager:

with timeout(0.5):
    ... work ...

…or decorating a function:

def work():

The exception may be configured, either by passing an exception instance, or by specifying an overriding exception class and/or value(s):

with timeout(0.5, RuntimeError("Work took too long")):
    ... work ...

with timeout(0.5, RuntimeError, "Work took too long"):
    ... work ...

with timeout(0.5, exc=RuntimeError):
    ... work ...

with timeout(0.5, value="Work took too long"):
    ... work ...

with timeout(0.5, value=(2, "Took too long", '')):
    ... work ...

The timeout exception defaults to TimeoutError("Operation timed out").

Note: timeout is implemented via signal, and as such may not be applied outside of a process’s main thread.


signalled-timeout is a Python distribution, which may be installed via easy_install or pip, e.g.:

pip install signalled-timeout

…or, from source:

python install


To test the distribution on your system, execute its test command:

python test

Project details

Download files

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

Files for signalled-timeout, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size signalled-timeout-1.0.0.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page