I need to take a picture in each second in an infinite loop.
I've wrote 2 different python scripts: one with camera.capture()
and another with camera.capture_continuous()
In both cases, I see the Buff/Cache memory keeps increasing until the maximum possible (after ~30 minutes).
When I stop the script, the memory stops increasing but doesn't decrease. The only way I've found to decrease the buff/cache memory to a level similar to before launching the script is to remove all the created jpeg files.... Do you have an idea from where is the memory leak? Is it already known?
Here is my code:
with PiCamera() as camera:
# Picamera object / objet Picamera
camera.resolution = (cmd['camera_resolution'][0],cmd['camera_resolution'][1])
camera.iso = cmd['camera_iso']
camera.start_preview()
time.sleep(2)
try:
for i, image_filename in enumerate(camera.capture_continuous('image_{counter}.jpg', format='jpeg')):
time.sleep(cmd['sleep_time'])
if os.path.isfile(cmd['stopfile']):
break
camera.stop_preview()
camera.close()
sys.exit(0)
except KeyboardInterrupt:
camera.stop_preview()
camera.close()
print ('Quit')
with PiCamera() as camera:
with
it is like theusing
statement in C# - meaning once you are done with the code inside there... it should automatically dispose of it (letting GC know the memory can be free'd up) so maybe its not thatwith
causing the problem. Again.. I dont know much about Python lifecycle and how it deals with stuff inside thewith
- in C# anything inside theusing
get marked disposed before the using is disposed. Maybe it is PiCamera not behaving properly and instead of getting disposed it hangs around doing something "magic" - who knows. play around a bit