Limit the function execution time
Project description
Limit the function execution time
This module provides a decorator which runs the function in a separate multiprocessing.Process and sends SIGKILL after the specified timeout if the function didn't complete.
Requirements
- Python 3.7+ (needed for multiprocessing.Process.kill)
Install
pip install kill-timeout
Usage
from kill_timeout import kill_timeout
limit_in_seconds = 5
@kill_timeout(limit_in_seconds)
def long_running_function(**parameters):
"""Function which makes some computations
It could take too long for some parameters.
"""
...
try:
result = long_running_function(iterations=9001)
print("Function returned: %r" % result)
except TimeoutError:
print("Function didn't finished in %d seconds" % limit_in_seconds)
except Exception:
print("Function failed with its internal error! Its original traceback:")
raise
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
kill_timeout-0.0.3.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for kill_timeout-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bd2934c091f50cb397f7eddef9a4f95e12a1afc45f1ecdc32274d44fc263ba4 |
|
MD5 | da5cbb6634ef3ac57a053cc77b2b6ff1 |
|
BLAKE2b-256 | 792744f23715790c0c33a88063e751d9f2b7209fe74c394a747f4cc5d4a93a8f |