diff options
| author | Michele Simionato <michele.simionato@gmail.com> | 2019-03-16 07:57:13 +0100 |
|---|---|---|
| committer | Michele Simionato <michele.simionato@gmail.com> | 2019-03-16 07:57:13 +0100 |
| commit | 1c14fd60039e5c0ea216f22cabbca96acfd50e02 (patch) | |
| tree | 73677cb243428ec7db35ea102847dd25bc4f5db9 | |
| parent | 6d3c7f75a4078ed9b8ce64fb6cc5a87e1bad09c0 (diff) | |
| download | python-decorator-git-1c14fd60039e5c0ea216f22cabbca96acfd50e02.tar.gz | |
Fixed README.rst
| -rw-r--r-- | README.rst | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -58,3 +58,33 @@ The documentation has been moved to https://raw.githubusercontent.com/micheles/d From there you can get a PDF version by simply using the print functionality of your browser. +For the impatient +----------------- + +Here is an example of how to define a family of decorators tracing slow +operations: + +.. code-block:: python + + from decorator import decorator + + @decorator + def warn_slow(func, timelimit=60, *args, **kw): + t0 = time.time() + result = func(*args, **kw) + dt = time.time() - t0 + if dt > timelimit: + logging.warn('%s took %d seconds', func.__name__, dt) + else: + logging.info('%s took %d seconds', func.__name__, dt) + return result + + @warn_slow # warn if it takes more than 1 minute + def preprocess_input_files(inputdir, tempdir): + ... + + @warn_slow(timelimit=600) # warn if it takes more than 10 minutes + def run_calculation(tempdir, outdir): + ... + +Enjoy! |
