Skip to main content

Easy timeout actions for any Python code with contextmanagers or decorators

Project description

Overdue

Conveniently stop Python code from running when it is taking too long on Python 3.10+. Ships with type annotations and depends at runtime on nothing but Python itself.

For older Pythons, consider stopit.

Installation

$ pip install overdue or whatever is the equivalent in your favorite package manager.

Using a context manager

Without exceptions:

from overdue import timeout_set_to

with timeout_set_to(0.25) as timeout:
    # Slow code
if timeout.triggered:
    # Handle timeout

With an exception:

from overdue import timeout_set_to, TaskAbortedError

try:
    with timeout_set_to(0.25, raise_exception=True):
        # Slow code
except TaskAbortedError:
    # Handle timeout

Using a decorator

With an exception:

from overdue import timecapped_to, TaskAbortedError

@timecapped_to(0.25)
def my_slow_function() -> None:
    # Slow code

try:
    my_slow_function()
except TaskAbortedError:
    # Handle timeout

Without exceptions:

from overdue import in_time_or_none

@in_time_or_none(0.25)
def my_slow_function() -> int:
    # Slow code
    return 7

if (result := my_slow_function()) is None:
    # Handle timeout

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

overdue-0.1.3.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

overdue-0.1.3-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file overdue-0.1.3.tar.gz.

File metadata

  • Download URL: overdue-0.1.3.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.9

File hashes

Hashes for overdue-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9fa1831e99238eb4653779b1361c2c2feffd55ef14d68105faed8c7b80bf8dc7
MD5 1d4d9295ea55f5b0c5bac6239e487c7f
BLAKE2b-256 ac9c9811e63c86def344c76d212b9be74bf561f54e2e806bdbb5fed2cb030ead

See more details on using hashes here.

File details

Details for the file overdue-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: overdue-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.9

File hashes

Hashes for overdue-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eafbb496d213d7f33fbc5cf9b9138373323bbeabe1199f6c491bcafca01901c4
MD5 4eff83a6422680858acd838c14863fab
BLAKE2b-256 11552a7ab7636141715cee99bf0cc561709b1e11a297a099e9c8ee9cf26dd740

See more details on using hashes here.

Supported by

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