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 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file overdue-0.1.5.tar.gz.
File metadata
- Download URL: overdue-0.1.5.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6781da739f802d904f4a0d404824f315c5cb1911b309f7a6d4b5f465374cd2da
|
|
| MD5 |
f1d4822bbb2722b89f531ab76e4344a2
|
|
| BLAKE2b-256 |
0f287a099f4f699c23b0b7701a9901325b4fd1c3812bb45be9438f97a16d25ed
|
File details
Details for the file overdue-0.1.5-py3-none-any.whl.
File metadata
- Download URL: overdue-0.1.5-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ece13e9f7ef8636b9c906143b9573a333ef81953e38d870b4e0732c0d7ce063
|
|
| MD5 |
fbde01ab30b8c99cd0ad7af9de391781
|
|
| BLAKE2b-256 |
53012a14f0d4e9777452f444fbb96dabc8abedf482ae140a1e22a05baab05813
|