MatsAndT / Astro-pi-kvadda-19-20

MIT License
2 stars 1 forks source link

Deleting old images when full not working #32

Closed MatsAndT closed 4 years ago

MatsAndT commented 4 years ago

Terminal Error

It was like the img did not have a id

Log Error / Log

INFO:2020-02-07 10:53:30,043:__main__:manager:On cycle1558
DEBUG:2020-02-07 10:53:30,044:__main__:get_compass:function get_compass start
INFO:2020-02-07 10:53:30,044:__main__:get_compass:Returned compass info
DEBUG:2020-02-07 10:53:30,062:__main__:get_img:function get_img start
INFO:2020-02-07 10:53:30,062:__main__:get_img:Captured image
CRITICAL:2020-02-07 10:53:30,823:__main__:get_img:Could not get image: Traceback (most recent call last):
  File "main.py", line 85, in get_img
    img = image.Image.capture_image()
  File "/home/pi/AstroPi/astro-memory/image/image.py", line 130, in capture_image
    picam.capture("{}{}.jpg".format(path, id))
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1421, in capture
    if not encoder.wait(self.CAPTURE_TIMEOUT):
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 398, in wait
    raise self.exception
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 267, in _callback
    stop = self._callback_write(buf)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1019, in _callback_write
    super(PiOneImageEncoder, self)._callback_write(buf, key)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 298, in _callback_write
    written = output.write(buf.data)
OSError: [Errno 28] No space left on device

INFO:2020-02-07 10:53:30,824:__main__:get_img:Captured image
CRITICAL:2020-02-07 10:53:31,565:__main__:get_img:Could not get image: Traceback (most recent call last):
  File "main.py", line 85, in get_img
    img = image.Image.capture_image()
  File "/home/pi/AstroPi/astro-memory/image/image.py", line 130, in capture_image
    picam.capture("{}{}.jpg".format(path, id))
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1421, in capture
    if not encoder.wait(self.CAPTURE_TIMEOUT):
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 398, in wait
    raise self.exception
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 267, in _callback
    stop = self._callback_write(buf)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1019, in _callback_write
    super(PiOneImageEncoder, self)._callback_write(buf, key)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 298, in _callback_write
    written = output.write(buf.data)
OSError: [Errno 28] No space left on device

INFO:2020-02-07 10:53:31,565:__main__:get_img:Captured image
CRITICAL:2020-02-07 10:53:32,393:__main__:get_img:Could not get image: Traceback (most recent call last):
  File "main.py", line 85, in get_img
    img = image.Image.capture_image()
  File "/home/pi/AstroPi/astro-memory/image/image.py", line 130, in capture_image
    picam.capture("{}{}.jpg".format(path, id))
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1421, in capture
    if not encoder.wait(self.CAPTURE_TIMEOUT):
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 398, in wait
    raise self.exception
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 267, in _callback
    stop = self._callback_write(buf)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1019, in _callback_write
    super(PiOneImageEncoder, self)._callback_write(buf, key)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 298, in _callback_write
    written = output.write(buf.data)
OSError: [Errno 28] No space left on device

DEBUG:2020-02-07 10:53:32,394:__main__:get_img:function get_img end
INFO:2020-02-07 10:53:32,399:__main__:stop_prosses:function stop_prosess start

The issue could be that the sd card is too small and not the data have existed 3 GB.

MatsAndT commented 4 years ago
pi@raspberrypi:~/AstroPi/astro-memory $ du -sh data
3.5G    data

It is the folder where the images and DB is stored, this should be less than 3 GB.

pi@raspberrypi:~/AstroPi/astro-memory $ du -sh data/database.sqlite
116K    data/database.sqlite
MatsAndT commented 4 years ago

Code for this issue, see Space-not-left-fix-#32

MatsAndT commented 4 years ago

Full Log

log.log

MatsAndT commented 4 years ago
>>> os.path.getsize("./data/imgs/")
36864
>>> os.path.getsize("./data/")
4096
>>> os.path.getsize("./data/imgs/"+"../")
4096
MatsAndT commented 4 years ago

Posible fix

https://gist.github.com/SteveClement/3755572

import os
def get_size(start_path = '.'):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(start_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            ##total_size += os.path.getsize(fp)
            total_size += (os.path.getsize(fp) if os.path.isfile(fp) else 0)
    return total_size

print get_size()

or https://www.daniweb.com/programming/software-development/code/216951/size-of-a-file-folder-directory-python

# determine size of a given folder in MBytes
import os
# pick a folder you have ...
folder = 'D:\\zz1'
folder_size = 0
for (path, dirs, files) in os.walk(folder):
  for file in files:
    filename = os.path.join(path, file)
    folder_size += os.path.getsize(filename)
print "Folder = %0.1f MB" % (folder_size/(1024*1024.0))

or https://stackoverflow.com/a/1392549/7419883

import os
sum(os.path.getsize(f) for f in os.listdir('.') if os.path.isfile(f))

2019

from pathlib import Path

root_directory = Path('.')
sum(f.stat().st_size for f in root_directory.glob('**/*') if f.is_file() )
pYtato-KK commented 4 years ago

Commit is unrelated to this issue