Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
tests/ | 25-Apr-2025 | - | 122 | 88 | ||
timeout_decorator/ | 25-Apr-2025 | - | 210 | 160 | ||
.gitignore | D | 25-Apr-2025 | 353 | 44 | 36 | |
.travis.yml | D | 25-Apr-2025 | 515 | 22 | 21 | |
Android.bp | D | 25-Apr-2025 | 928 | 30 | 27 | |
CHANGES.rst | D | 25-Apr-2025 | 279 | 19 | 12 | |
LICENSE | D | 25-Apr-2025 | 1.1 KiB | 23 | 18 | |
LICENSE.txt | D | 25-Apr-2025 | 1.1 KiB | 23 | 18 | |
MANIFEST.in | D | 25-Apr-2025 | 14 | 2 | 1 | |
METADATA | D | 25-Apr-2025 | 379 | 17 | 16 | |
MODULE_LICENSE_MIT | D | 25-Apr-2025 | 0 | |||
Makefile | D | 25-Apr-2025 | 222 | 12 | 6 | |
NOTICE | D | 25-Apr-2025 | 1.1 KiB | 23 | 18 | |
OWNERS | D | 25-Apr-2025 | 160 | 9 | 7 | |
README.rst | D | 25-Apr-2025 | 2.7 KiB | 112 | 77 | |
setup.py | D | 25-Apr-2025 | 1 KiB | 39 | 32 | |
tox.ini | D | 25-Apr-2025 | 289 | 18 | 15 |
README.rst
1Timeout decorator 2================= 3 4|Build Status| |Pypi Status| |Coveralls Status| 5 6Installation 7------------ 8 9From source code: 10 11:: 12 13 python setup.py install 14 15From pypi: 16 17:: 18 19 pip install timeout-decorator 20 21Usage 22----- 23 24:: 25 26 import time 27 import timeout_decorator 28 29 @timeout_decorator.timeout(5) 30 def mytest(): 31 print("Start") 32 for i in range(1,10): 33 time.sleep(1) 34 print("{} seconds have passed".format(i)) 35 36 if __name__ == '__main__': 37 mytest() 38 39Specify an alternate exception to raise on timeout: 40 41:: 42 43 import time 44 import timeout_decorator 45 46 @timeout_decorator.timeout(5, timeout_exception=StopIteration) 47 def mytest(): 48 print("Start") 49 for i in range(1,10): 50 time.sleep(1) 51 print("{} seconds have passed".format(i)) 52 53 if __name__ == '__main__': 54 mytest() 55 56Multithreading 57-------------- 58 59By default, timeout-decorator uses signals to limit the execution time 60of the given function. This appoach does not work if your function is 61executed not in a main thread (for example if it's a worker thread of 62the web application). There is alternative timeout strategy for this 63case - by using multiprocessing. To use it, just pass 64``use_signals=False`` to the timeout decorator function: 65 66:: 67 68 import time 69 import timeout_decorator 70 71 @timeout_decorator.timeout(5, use_signals=False) 72 def mytest(): 73 print "Start" 74 for i in range(1,10): 75 time.sleep(1) 76 print("{} seconds have passed".format(i)) 77 78 if __name__ == '__main__': 79 mytest() 80 81.. warning:: 82 Make sure that in case of multiprocessing strategy for timeout, your function does not return objects which cannot 83 be pickled, otherwise it will fail at marshalling it between master and child processes. 84 85 86Acknowledgement 87--------------- 88 89Derived from 90http://www.saltycrane.com/blog/2010/04/using-python-timeout-decorator-uploading-s3/ 91and https://code.google.com/p/verse-quiz/source/browse/trunk/timeout.py 92 93Contribute 94---------- 95 96I would love for you to fork and send me pull request for this project. 97Please contribute. 98 99License 100------- 101 102This software is licensed under the `MIT license <http://en.wikipedia.org/wiki/MIT_License>`_ 103 104See `License file <https://github.com/pnpnpn/timeout-decorator/blob/master/LICENSE.txt>`_ 105 106.. |Build Status| image:: https://travis-ci.org/pnpnpn/timeout-decorator.svg?branch=master 107 :target: https://travis-ci.org/pnpnpn/timeout-decorator 108.. |Pypi Status| image:: https://badge.fury.io/py/timeout-decorator.svg 109 :target: https://badge.fury.io/py/timeout-decorator 110.. |Coveralls Status| image:: https://coveralls.io/repos/pnpnpn/timeout-decorator/badge.png?branch=master 111 :target: https://coveralls.io/r/pnpnpn/timeout-decorator 112