• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

tests/25-Apr-2025-12288

timeout_decorator/25-Apr-2025-210160

.gitignoreD25-Apr-2025353 4436

.travis.ymlD25-Apr-2025515 2221

Android.bpD25-Apr-2025928 3027

CHANGES.rstD25-Apr-2025279 1912

LICENSED25-Apr-20251.1 KiB2318

LICENSE.txtD25-Apr-20251.1 KiB2318

MANIFEST.inD25-Apr-202514 21

METADATAD25-Apr-2025379 1716

MODULE_LICENSE_MITD25-Apr-20250

MakefileD25-Apr-2025222 126

NOTICED25-Apr-20251.1 KiB2318

OWNERSD25-Apr-2025160 97

README.rstD25-Apr-20252.7 KiB11277

setup.pyD25-Apr-20251 KiB3932

tox.iniD25-Apr-2025289 1815

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