Skip to content

Instantly share code, notes, and snippets.

@mzupan
Created October 19, 2014 02:07
Show Gist options
  • Save mzupan/44f067e52f56b98fdf1b to your computer and use it in GitHub Desktop.
Save mzupan/44f067e52f56b98fdf1b to your computer and use it in GitHub Desktop.
python decorator to time a fabric function
from fabric.api import env, run
import time
env.hosts = ['web01-east']
def logtime(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
print '%r (%r, %r) %2.2f sec' % (method.__name__, args, kw, te-ts)
return result
return timed
@logtime
def sleep():
run("sleep 10")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment