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.3.tar.gz
(13.4 kB
view hashes)
Built Distribution
Close
Hashes for timeout_executor-0.3.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33ca9e2d2ebd82d275ec60d188bbd90354a0d432c4506900f5e14d22dd041eaf |
|
MD5 | d21e2ab7fc547e56c3acc91f4cf66697 |
|
BLAKE2b-256 | a3c2d75c8b45958ae9b45bbc4e877b30ff6d9405aa91845eef8b4db4c48f0ef5 |