Skip to main content

execute with timeout

Project description

timeout-executor

License: MIT github action PyPI version python version

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


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)

Uploaded Source

Built Distribution

timeout_executor-0.3.3-py3-none-any.whl (13.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page