OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

memory_usage from memory_profiler calling the function multiple times

  • Thread starter Thread starter Andrew Groves
  • Start date Start date
A

Andrew Groves

Guest
Ive wrote a decorator to run memory_usage and get the peak to logging, however it sometimes calls the function multiple times.

Code:
def profile_memory(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        logging.info(f"Starting {func.__name__}")
        mem_usage = memory_usage((func,args,kwargs), interval=1)
        logging.info(f"Max memory usage is {round(max(mem_usage),2)} mb for {func.__name__}")

    return wrapper

I dont really know what to try, it does it for multiple function in my package
<p>Ive wrote a decorator to run memory_usage and get the peak to logging, however it sometimes calls the function multiple times.</p>
<pre><code>def profile_memory(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
logging.info(f"Starting {func.__name__}")
mem_usage = memory_usage((func,args,kwargs), interval=1)
logging.info(f"Max memory usage is {round(max(mem_usage),2)} mb for {func.__name__}")

return wrapper
</code></pre>
<p>I dont really know what to try, it does it for multiple function in my package</p>
 

Latest posts

Top