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.

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

with timeout_set_to(0.25, raise_exception=True):
    try:
        # 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.2.tar.gz (9.9 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.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for overdue-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2d6ad0179bd54bdb4ef7ccf1430f69f65e58676584b795dd469a91788826ce61
MD5 2420d82ea3ed4726c2f4d36583f7d9bf
BLAKE2b-256 acd22b0c5087a515e5fdc569cbc16f4652594f71bc85da971070b5240961b7a2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for overdue-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3145ab9c09924ebc8a9f0a14cced4a068476b6ed83019b774df45a1f80d9446
MD5 25e0281c8476e7411996a5fcb1e5f2d9
BLAKE2b-256 1f2061a164183f12b6296f1a6808ded0981a73df55b30988d2cf397332546256

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