All Projects → pnpnpn → Timeout Decorator

pnpnpn / Timeout Decorator

Licence: mit
Timeout decorator for Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Timeout Decorator

kiwi
Built using only nodejs core. Lightweight, intuitive together with great performance and response timing.
Stars: ✭ 45 (-88.78%)
Mutual labels:  decorators
Helpful Decorators
Helpful decorators for typescript projects
Stars: ✭ 263 (-34.41%)
Mutual labels:  decorators
Ng Metadata
Angular 2 decorators and utils for Angular 1.x
Stars: ✭ 356 (-11.22%)
Mutual labels:  decorators
state inspector
State change & method call logger. A debugging tool for instance variables and method calls.
Stars: ✭ 24 (-94.01%)
Mutual labels:  decorators
giuseppe
A controller routing system for expressJS with TypeScript decorators and annotations
Stars: ✭ 49 (-87.78%)
Mutual labels:  decorators
Pebble
Multi threading and processing eye-candy.
Stars: ✭ 276 (-31.17%)
Mutual labels:  decorators
toxic-decorators
Library of Javascript decorators
Stars: ✭ 26 (-93.52%)
Mutual labels:  decorators
Ratelimit
API Rate Limit Decorator
Stars: ✭ 365 (-8.98%)
Mutual labels:  decorators
Rxweb
Tons of extensively featured packages for Angular, VUE and React Projects
Stars: ✭ 262 (-34.66%)
Mutual labels:  decorators
Ngx Auto Unsubscribe
Class decorator that will automatically unsubscribe from observables
Stars: ✭ 337 (-15.96%)
Mutual labels:  decorators
bind-observable
Provides a typescript decorator which binds class properties to observable companion properties.
Stars: ✭ 15 (-96.26%)
Mutual labels:  decorators
vue-decorator
Custom decorators to vue-class-component that fits Vue 3
Stars: ✭ 31 (-92.27%)
Mutual labels:  decorators
Nestcloud
A NodeJS micro-service solution, writing by Typescript language and NestJS framework.
Stars: ✭ 290 (-27.68%)
Mutual labels:  decorators
elasticmock
Python Elasticsearch Mock for test purposes
Stars: ✭ 98 (-75.56%)
Mutual labels:  decorators
Cachier
Persistent, stale-free, local and cross-machine caching for Python functions.
Stars: ✭ 359 (-10.47%)
Mutual labels:  decorators
route-decorators
ES7 decorators that simplify Koa and Express route creation
Stars: ✭ 71 (-82.29%)
Mutual labels:  decorators
Decorator
Function decorators for Elixir
Stars: ✭ 278 (-30.67%)
Mutual labels:  decorators
Ng2 Webstorage
Localstorage and sessionstorage manager - Angular service
Stars: ✭ 395 (-1.5%)
Mutual labels:  decorators
Ember Decorators
Useful decorators for Ember applications.
Stars: ✭ 360 (-10.22%)
Mutual labels:  decorators
Warthog
GraphQL API Framework with strong conventions and auto-generated schema
Stars: ✭ 316 (-21.2%)
Mutual labels:  decorators

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].