I have a raspberry pi with raspbian on it, and I've created a python script that I need to have running all the time. The problem is that after running for an hour or so, the script suddenly stops, and the python process shuts down. I have no idea why, and I'm very new to linux so I don't know how to debug it or anything. I don't think it's a memory issue because during the while loop I free and reinit all objects used. How can I find out what the issue is, or at least automatically restart the program once it stops?
This is the code:
import time
import sys
import ftputil
import pygame
import pygame.camera
import logging
pygame.camera.init()
#pygame.camera.list_camera() #Camera detected or not
cam = pygame.camera.Camera("/dev/video0",(640,480))
count = 5
logging.basicConfig(filename='log.log', level=logging.INFO)
logging.info(str(time.time())+" : Script was started")
while True:
cam.start()
img = cam.get_image()
pygame.image.save(img,"current.jpeg")
cam.stop()
host = ftputil.FTPHost(**)
host.upload("./current.jpeg", "/domains/*/public_html/webcam.jpg", mode='b')
host.close()
if not count:
host = ftputil.FTPHost(**)
filename = str(time.time()) + ".jpg"
host.upload("./current.jpeg", "/webcamarchive/"+filename, mode='b')
host.close()
count = 10
logging.info(str(time.time())+": Still running")
count -= 1
time.sleep(3)
I run the script from ssh. But I would like to make it start when the computer starts up, as well, how would I do this?
cam.get_image()orhost.upload()or whatever, could possibly raise an exception?if !count:is aSyntaxErrorin Python. Obscuring theFTPHostparams is fine (although testing to see whether it's relevant, and completely removing all the FTP stuff if you can still repro the problem without it, would be even better). But as much as possible, try to post code that actually runs and exhibits the problem you're trying to test.