Created
October 19, 2014 02:07
-
-
Save mzupan/44f067e52f56b98fdf1b to your computer and use it in GitHub Desktop.
python decorator to time a fabric function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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