Skip to main content

A signal based timeout context manager

Project description

https://img.shields.io/travis/AntoineCezar/timeoutcontext.svg https://img.shields.io/badge/docs-latest-brightgreen.svg https://img.shields.io/coveralls/AntoineCezar/timeoutcontext.svg https://img.shields.io/pypi/v/timeoutcontext.svg

A signal based timeout context manager and decorator.

Since it is signal based this package can not work under Windows operating system.

Usage

As a context manager:

import sys
from time import sleep
from timeoutcontext import timeout
if sys.version_info < (3, 3):
    from timeoutcontext._timeout import TimeoutError

try:
    with timeout(1):
        sleep(2)
except TimeoutError:
    print('timeout')

As a decorator:

import sys
from time import sleep
from timeoutcontext import timeout
if sys.version_info < (3, 3):
    from timeoutcontext._timeout import TimeoutError

@timeout(1)
def wait():
    sleep(2)

try:
    wait()
except TimeoutError:
    print('timeout')

License

  • Free software: BSD license

History

1.2.0 (2018-03-11)

  • Allow sub-second timeout

1.1.1 (2016-09-05)

  • Fix README code exemples

1.1.0 (2016-09-05)

  • Add the “Not working on Windows operating system” notice

  • Rename TimeoutException to TimeoutError

1.0.0 (2016-01-23)

  • First release on PyPI.

Project details


Download files

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

Source Distribution

timeoutcontext-1.2.0.tar.gz (12.9 kB view details)

Uploaded Source

File details

Details for the file timeoutcontext-1.2.0.tar.gz.

File metadata

File hashes

Hashes for timeoutcontext-1.2.0.tar.gz
Algorithm Hash digest
SHA256 f4ac63bde9d22e300de5e9f0079648049b51492b4af74d3e6c109fd0c043ad82
MD5 7f662aea372fc842b3e914e539439332
BLAKE2b-256 cac2c62924077e30e0dd723ae1169f5d92d7cea0872e9153b04ad0c701e56394

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page