{"id":13781922,"url":"https://github.com/pnpnpn/timeout-decorator","last_synced_at":"2025-10-21T13:04:35.501Z","repository":{"id":5932900,"uuid":"7152983","full_name":"pnpnpn/timeout-decorator","owner":"pnpnpn","description":"Timeout decorator for Python","archived":false,"fork":false,"pushed_at":"2024-01-12T01:04:32.000Z","size":45,"stargazers_count":641,"open_issues_count":41,"forks_count":95,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-04T17:01:52.422Z","etag":null,"topics":["decorators","python","python-decorators","timeout","timeout-library"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pnpnpn.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2012-12-13T18:20:56.000Z","updated_at":"2025-04-30T03:00:40.000Z","dependencies_parsed_at":"2024-01-16T01:24:08.822Z","dependency_job_id":"b92c99ea-3227-4121-86e1-704c92f39af6","html_url":"https://github.com/pnpnpn/timeout-decorator","commit_stats":{"total_commits":53,"total_committers":16,"mean_commits":3.3125,"dds":0.7735849056603774,"last_synced_commit":"9fbc3ef5b6f8f8cba2eb7ba795813d6ec543e265"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnpnpn%2Ftimeout-decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnpnpn%2Ftimeout-decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnpnpn%2Ftimeout-decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnpnpn%2Ftimeout-decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pnpnpn","download_url":"https://codeload.github.com/pnpnpn/timeout-decorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253509782,"owners_count":21919589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decorators","python","python-decorators","timeout","timeout-library"],"created_at":"2024-08-03T18:01:30.801Z","updated_at":"2025-10-21T13:04:35.384Z","avatar_url":"https://github.com/pnpnpn.png","language":"Python","readme":"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 \u003chttp://en.wikipedia.org/wiki/MIT_License\u003e`_\n\nSee `License file \u003chttps://github.com/pnpnpn/timeout-decorator/blob/master/LICENSE.txt\u003e`_\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","funding_links":[],"categories":["Python decorator in the wild"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnpnpn%2Ftimeout-decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpnpnpn%2Ftimeout-decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnpnpn%2Ftimeout-decorator/lists"}