Я пытаюсь измерить использование памяти для функции python, воссоздав пример, приведенный в документации к memory_profiler.Мне просто нужен выходной вектор использования памяти каждые 0,1 секунды, из которого я могу найти максимальное использование памяти.Когда я запускаю его, у меня возникает ошибка во время выполнения, которую я не могу понять.
Я изменил код различными способами и посмотрел онлайн, но не могу его исправить.
from memory_profiler import memory_usage
import time
from time import sleep
def f():
# a function that has growing memory requirements with time
a = 1
sleep(.1)
b = a*1000
sleep(.1)
c = b*1000
return a
mem_usage = memory_usage(f) # run function while tracking memory usage
every 0.1 seconds
print('Memory usage (in chunks of 0.1 seconds): %s' %mem_usage)
print('Maximum memory usage: %s' %max(mem_usage))
Я получаю следующую ошибку во время выполнения:
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start you
child processes and you have forgotten to use the proper idi
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.