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 datetime import timedelta
from overdue import timeout_set_to, TaskAbortedError
try:
with timeout_set_to(timedelta(milliseconds=250), 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
Metadata
Release files for overdue 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| overdue-0.1.5.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| overdue-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.8 kB
Release files / overdue-0.1.5.tar.gz
| Download URL | overdue-0.1.5.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6781da739f802d904f4a0d404824f315c5cb1911b309f7a6d4b5f465374cd2da
|
|
BLAKE2b-256 checksum How to use checksums |
0f287a099f4f699c23b0b7701a9901325b4fd1c3812bb45be9438f97a16d25ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Release files / overdue-0.1.5-py3-none-any.whl
| Download URL | overdue-0.1.5-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3ece13e9f7ef8636b9c906143b9573a333ef81953e38d870b4e0732c0d7ce063
|
|
BLAKE2b-256 checksum How to use checksums |
53012a14f0d4e9777452f444fbb96dabc8abedf482ae140a1e22a05baab05813
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|