I have i timing function and my main function. When i use only main function it runs fine, but when i use timing function as a decorator it raises an exception.
Timing function code:
def timing(function):
import time
t = time.time()
function()
t = time.time() - t
print('Program has been running for {} seconds.'.format(t))
I use it like this:
@timing
def main():
#some code
The decorator needs to return the decorated function:
def timing(function):
def wrapped():
import time
t = time.time()
function()
t = time.time() - t
print('Program has been running for {} seconds.'.format(t))
return wrapped
@timing
def main():
# some code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With