1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
Metadata-Version: 1.1
Name: timeout-decorator
Version: 0.5.0
Summary: Timeout decorator
Home-page: https://github.com/pnpnpn/timeout-decorator
Author: Patrick Ng
Author-email: pn.appdev@gmail.com
License: UNKNOWN
Description: Timeout decorator
=================
|Build Status| |Pypi Status| |Coveralls Status|
Installation
------------
From source code:
::
python setup.py install
From pypi:
::
pip install timeout-decorator
Usage
-----
::
import time
import timeout_decorator
@timeout_decorator.timeout(5)
def mytest():
print("Start")
for i in range(1,10):
time.sleep(1)
print("{} seconds have passed".format(i))
if __name__ == '__main__':
mytest()
Specify an alternate exception to raise on timeout:
::
import time
import timeout_decorator
@timeout_decorator.timeout(5, timeout_exception=StopIteration)
def mytest():
print("Start")
for i in range(1,10):
time.sleep(1)
print("{} seconds have passed".format(i))
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
import timeout_decorator
@timeout_decorator.timeout(5, use_signals=False)
def mytest():
print "Start"
for i in range(1,10):
time.sleep(1)
print("{} seconds have passed".format(i))
if __name__ == '__main__':
mytest()
.. warning::
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.
Acknowledgement
---------------
Derived from
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 <http://en.wikipedia.org/wiki/MIT_License>`_
See `License file <https://github.com/pnpnpn/timeout-decorator/blob/master/LICENSE.txt>`_
.. |Build Status| image:: https://travis-ci.org/pnpnpn/timeout-decorator.svg?branch=master
:target: https://travis-ci.org/pnpnpn/timeout-decorator
.. |Pypi Status| image:: https://badge.fury.io/py/timeout-decorator.svg
:target: https://badge.fury.io/py/timeout-decorator
.. |Coveralls Status| image:: https://coveralls.io/repos/pnpnpn/timeout-decorator/badge.png?branch=master
:target: https://coveralls.io/r/pnpnpn/timeout-decorator
Changelog
=========
0.3.1
-----
- Fixed issue with PicklingError causes the timeout to never be reached.
0.3.0
-----
- Added optional threading support via python multiprocessing (bubenkoff)
- Switched to pytest test runner (bubenkoff)
0.2.1
-----
- Initial public release
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|