문제 설명
메모리 부족으로 인해 루핑 프로그램이 멈춤 (Looping program freezes due to memory running out)
다음을 사용하여 동일한 확률적 프로그램을 100,000번 실행하고 있습니다. Loop 100000 각 루프 후에 데이터가 저장되지 않습니다.
약 30,000개의 루프 후에 프로그램이 멈춘 후 메모리 부족으로 가정합니다. 각 루프의 시작 부분에 메모리를 정리할 수 있는 항목이 있습니까?
Dell 노트북에서 Ubuntu를 사용하여 Python 프로그램을 실행하고 있습니다.
미리 감사합니다
각 루프 시작 시 다음과 같은 모든 파일이 지워집니다.
del resistance[:]
참조 솔루션
방법 1:
I don't know if this will help you specifically, but it is good for freeing up memory. Try importing gc
and call gc.collect()
right before and/or inside of the for loop.
방법 2:
Thanks everyone. I tried installing psutil, it installed in Unix but when I went to run it in Python it said psutil was not installed. Other people seem to get the same problem. I am running with gc.collect() and waiting to see what happens.
A question for silver. Why does Python keep allocating storage when I run del resistance[ : ]? as in:
Loops = 30000 for i range(Loops): del resistance[ : ]; for j in range(15): resistance[] = some_function;
(by Bob、Bilbo Baggins、Bob)