Skip to content

Instantly share code, notes, and snippets.

@frbry
Created June 30, 2014 17:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save frbry/caf7b576dd31eda4d5e6 to your computer and use it in GitHub Desktop.
A Simple Decorator for Simulating Delays in Method Calls
from functools import wraps
from random import randint
# Example Usage:
#
# @random_sleep
# def get_users(request):
# return database.users()
#
def random_sleep(f):
@wraps(f)
def wrapper(*args, **kwargs):
seconds = randint(1, 3) #Inclusive, change these boundaries as required
print 'Sleeping for ' + str(seconds) + ' seconds...'
time.sleep(seconds)
return f(*args, **kwargs)
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment