Currently, I tried to use the memory_profiler module to get the used memory like the following code:
from memory_profiler import memory_usage
memories=[]
def get_memory(mem,ended):
if ended:
highest_mem=max(mem)
print highest_mem
else:
memories.append(mem)
def f1():
#do something
ended=False
get_memory(memory_usage(),ended)
return #something
def f2():
#do something
ended=False
get_memory(memory_usage(),ended)
return #something
#main
f1()
f2()
ended=True
get_memory(memory_usage(),ended) #code end
>>>#output
# output
# highest memory
however, it did not successfully execute. It got stuck when ended=True and sent the value of memory_usage() and ended to the function of get_memory. It did not show any error as well., just waiting for long long time, then I force to stop executing. Anyone knows the better way or the solution?