execute with timeout
Project description
timeout-executor
how to install
$ pip install timeout_executor
# or
$ pip install "timeout_executor[uvloop]"
how to use
from __future__ import annotations
import time
from timeout_executor import AsyncResult, TimeoutExecutor
def sample_func() -> None:
time.sleep(10)
executor = TimeoutExecutor(1)
result = executor.apply(sample_func)
assert isinstance(result, AsyncResult)
try:
value = result.result()
except Exception as exc:
assert isinstance(exc, TimeoutError)
executor = TimeoutExecutor(1)
result = executor.apply(lambda: "done")
assert isinstance(result, AsyncResult)
value = result.result()
assert value == "done"
License
MIT, see LICENSE.
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
timeout_executor-0.3.2.tar.gz
(10.6 kB
view hashes)
Built Distribution
Close
Hashes for timeout_executor-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3789918b25acfd199f9b2284b9449f51405c7e28e3296e24c3affa080ba3f3a5 |
|
MD5 | df4e16591a088c02d5a13e3c4cdee15a |
|
BLAKE2b-256 | 2dbee08660636ed5f4f6106d4775f7cf71bc3e5ac922f1370c9e8f9eae35f582 |