Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ei-grad/kill-timeout
Python library to limit the function execution time
https://github.com/ei-grad/kill-timeout
Last synced: 15 days ago
JSON representation
Python library to limit the function execution time
- Host: GitHub
- URL: https://github.com/ei-grad/kill-timeout
- Owner: ei-grad
- Created: 2020-03-28T21:27:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-31T11:52:50.000Z (almost 5 years ago)
- Last Synced: 2024-10-16T21:06:09.966Z (3 months ago)
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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)
* tblib (to pass the traceback from separate process)Install
-------```bash
pip install kill-timeout
```Usage
-----```python
from kill_timeout import kill_timeoutlimit_in_seconds = 5
@kill_timeout(limit_in_seconds)
def long_running_function(**parameters):
"""Function which makes some computationsIt 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
```