I am attempting to use the memory_profiler
package. Example code below:
from memory_profiler import memory_usage
from time import sleep
def f():
# a function that with growing
# memory consumption
a = [0] * 1000
sleep(.1)
b = a * 100
sleep(.1)
c = b * 100
return a
mem_usage = memory_usage(f)
print('Memory usage (in chunks of .1 seconds): %s' % mem_usage)
print('Maximum memory usage: %s' % max(mem_usage))
The problem I am facing is that my actual function I want to try this on takes arguments.
def my_func(df1, df2):
new_df = pd.concat([df1, df2])
return new_df
Is there a way to create a shell function that runs my real function so that I can use this package?
def shell_function():
new_df = my_func(df1, df1)
return new_df
Code is from 2nd answer on this post: Tracking *maximum* memory usage by a Python function