Logging execution time with decorators
<p>After I tried unsuccessfully for a while, I am seeking help from this miraculous website. Now for my problem: I want to create a decorator that writes the elapsed execution time of a function (<strong><em>during</em> the execution of the function</strong>) into a logging file like:</p>

<pre><code>@log_time("log.txt", 35)
def some_function(...):
    ...
    return result
</code></pre>

<p>and</p>

<pre><code>from functools import wraps

def log_time(path_to_logfile, interval):
    ...
</code></pre>

<p>so that <code>log.txt</code> would look something like</p>

<pre><code>Time elapsed: 0h 0m 35s
Time elapsed: 0h 1m 10s
Time elapsed: 0h 1m 45s
</code></pre>

<p>Any ideas?</p>