From source code:
python setup.py install
pip install timeout-decorator
import time import timeout_decorator @timeout_decorator.timeout(5) def mytest(): print "Start" for i in range(1,10): time.sleep(1) print "%d seconds have passed" % i if __name__ == '__main__': mytest()
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 import timeout_decorator @timeout_decorator.timeout(5, use_signals=False) def mytest(): print "Start" for i in range(1,10): time.sleep(1) print "%d seconds have passed" % i if __name__ == '__main__': mytest()
Make sure that in case of multiprocessing strategy for timeout, your function does not return objects which cannot be pickled, otherwise it will fail at marshalling it between master and child processes.
I would love for you to fork and send me pull request for this project. Please contribute.
- Added optional threading support via python multiprocessing (bubenkoff)
- Switched to pytest test runner (bubenkoff)
- Initial public release
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size timeout-decorator-0.3.0.tar.gz (4.3 kB)||File type Source||Python version None||Upload date||Hashes View|