timeout-decorator


Nametimeout-decorator JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/pnpnpn/timeout-decorator
SummaryTimeout decorator
upload_time2020-11-15 00:53:06
maintainer
docs_urlNone
authorPatrick Ng
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            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
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pnpnpn/timeout-decorator",
    "name": "timeout-decorator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Patrick Ng",
    "author_email": "pn.appdev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/80/f8/0802dd14c58b5d3d72bb9caa4315535f58787a1dc50b81bbbcaaa15451be/timeout-decorator-0.5.0.tar.gz",
    "platform": "",
    "description": "Timeout decorator\n=================\n\n|Build Status| |Pypi Status| |Coveralls Status|\n\nInstallation\n------------\n\nFrom source code:\n\n::\n\n    python setup.py install\n\nFrom pypi:\n\n::\n\n    pip install timeout-decorator\n\nUsage\n-----\n\n::\n\n    import time\n    import timeout_decorator\n\n    @timeout_decorator.timeout(5)\n    def mytest():\n        print(\"Start\")\n        for i in range(1,10):\n            time.sleep(1)\n            print(\"{} seconds have passed\".format(i))\n\n    if __name__ == '__main__':\n        mytest()\n\nSpecify an alternate exception to raise on timeout:\n\n::\n\n    import time\n    import timeout_decorator\n\n    @timeout_decorator.timeout(5, timeout_exception=StopIteration)\n    def mytest():\n        print(\"Start\")\n        for i in range(1,10):\n            time.sleep(1)\n            print(\"{} seconds have passed\".format(i))\n\n    if __name__ == '__main__':\n        mytest()\n\nMultithreading\n--------------\n\nBy default, timeout-decorator uses signals to limit the execution time\nof the given function. This appoach does not work if your function is\nexecuted not in a main thread (for example if it's a worker thread of\nthe web application). There is alternative timeout strategy for this\ncase - by using multiprocessing. To use it, just pass\n``use_signals=False`` to the timeout decorator function:\n\n::\n\n    import time\n    import timeout_decorator\n\n    @timeout_decorator.timeout(5, use_signals=False)\n    def mytest():\n        print \"Start\"\n        for i in range(1,10):\n            time.sleep(1)\n            print(\"{} seconds have passed\".format(i))\n\n    if __name__ == '__main__':\n        mytest()\n\n.. warning::\n    Make sure that in case of multiprocessing strategy for timeout, your function does not return objects which cannot\n    be pickled, otherwise it will fail at marshalling it between master and child processes.\n\n\nAcknowledgement\n---------------\n\nDerived from\nhttp://www.saltycrane.com/blog/2010/04/using-python-timeout-decorator-uploading-s3/\nand https://code.google.com/p/verse-quiz/source/browse/trunk/timeout.py\n\nContribute\n----------\n\nI would love for you to fork and send me pull request for this project.\nPlease contribute.\n\nLicense\n-------\n\nThis software is licensed under the `MIT license <http://en.wikipedia.org/wiki/MIT_License>`_\n\nSee `License file <https://github.com/pnpnpn/timeout-decorator/blob/master/LICENSE.txt>`_\n\n.. |Build Status| image:: https://travis-ci.org/pnpnpn/timeout-decorator.svg?branch=master\n   :target: https://travis-ci.org/pnpnpn/timeout-decorator\n.. |Pypi Status| image:: https://badge.fury.io/py/timeout-decorator.svg\n    :target: https://badge.fury.io/py/timeout-decorator\n.. |Coveralls Status| image:: https://coveralls.io/repos/pnpnpn/timeout-decorator/badge.png?branch=master\n    :target: https://coveralls.io/r/pnpnpn/timeout-decorator\n\nChangelog\n=========\n\n0.3.1\n-----\n- Fixed issue with PicklingError causes the timeout to never be reached.\n\n0.3.0\n-----\n\n- Added optional threading support via python multiprocessing (bubenkoff)\n- Switched to pytest test runner (bubenkoff)\n\n\n0.2.1\n-----\n\n- Initial public release",
    "bugtrack_url": null,
    "license": "",
    "summary": "Timeout decorator",
    "version": "0.5.0",
    "project_urls": {
        "Homepage": "https://github.com/pnpnpn/timeout-decorator"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "80f80802dd14c58b5d3d72bb9caa4315535f58787a1dc50b81bbbcaaa15451be",
                "md5": "8545649e70b3ca43bcff11f08a996c3e",
                "sha256": "6a2f2f58db1c5b24a2cc79de6345760377ad8bdc13813f5265f6c3e63d16b3d7"
            },
            "downloads": -1,
            "filename": "timeout-decorator-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8545649e70b3ca43bcff11f08a996c3e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4754,
            "upload_time": "2020-11-15T00:53:06",
            "upload_time_iso_8601": "2020-11-15T00:53:06.506211Z",
            "url": "https://files.pythonhosted.org/packages/80/f8/0802dd14c58b5d3d72bb9caa4315535f58787a1dc50b81bbbcaaa15451be/timeout-decorator-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-11-15 00:53:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pnpnpn",
    "github_project": "timeout-decorator",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "timeout-decorator"
}
        
Elapsed time: 0.24937s