Celery Timeout decorator
Project description
Installation
From source code:
python setup.py install
From pypi:
pip install process-timer
Usage
import time from process_timer import timeout @timeout(5) def mytest(): print("Start") for i in range(1,10): time.sleep(1) print("{i} seconds have passed") if __name__ == '__main__': mytest()
Specify an alternate exception to raise on timeout:
import time from process_timer import timeout @timeout(5, timeout_exception=StopIteration) def mytest(): print("Start") for i in range(1,10): time.sleep(1) print(f"{i} seconds have passed") if __name__ == '__main__': mytest()
Multithreading
By default, timeout-decorator uses signals to limit the execution time of the given function. This appoach does not work if your function is executed not in a main thread (for example if it’s a worker thread of the web application). There is alternative timeout strategy for this case - by using multiprocessing. To use it, just pass use_signals=False to the timeout decorator function:
import time from process_timer import timeout import os @timeout(5, use_signals=False) def mytest(): print("Start") for i in range(1,10): os.system('sleep 1') print(f"{i} seconds have passed") if __name__ == '__main__': mytest()
Acknowledgement
Derived from Derived from https://github.com/pnpnpn/timeout-decorator to make it work in processes are not allowed to spawn it’s child processes. Ex: celery tasks http://www.saltycrane.com/blog/2010/04/using-python-timeout-decorator-uploading-s3/ and https://code.google.com/p/verse-quiz/source/browse/trunk/timeout.py
Contribute
I would love for you to fork and send me pull request for this project. Please contribute.
License
This software is licensed under the MIT license
See License file
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 Distributions
Built Distributions
Hashes for process_timer-1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 012858590637418fa0596fc58e9a65e1e7c3d18f80f188a9c2d595b397f13762 |
|
MD5 | cb44287a1bb64d8a2b9eab81c3c06d33 |
|
BLAKE2b-256 | a970f8f10f2aae14b21eda5aa3f129151ff71e5a58f6447ca8fab9472980b766 |