Skip to content
破仑的博客
Go back

Python 代码段

Tools

From: http://fredericiana.com/2014/11/14/settimeout-python-delay/

import threading
from functools import wraps

def delay(delay=0.):
    """
    Decorator delaying the execution of a function for a while.
    """
    def wrap(f):
        @wraps(f)
        def delayed(*args, **kwargs):
            timer = threading.Timer(delay, f, args=args, kwargs=kwargs)
            timer.start()
        return delayed
    return wrap

@delay(3.0)
def my_func(arg1, arg2):
    print arg1, arg2


if __name__ == '__main__':
    my_func('Hello', 'world')

Share this post on:

Previous Post
Node 备忘
Next Post
JavaScript 代码段