This is the error I get : picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
import numpy as np
import os
from picamera import PiCamera
from time import sleep
from gpiozero import LED
l = LED(21)
camera = PiCamera()
camera.rotation = 180
filename = "frame.png"
while 1:
try:
camera.capture(filename)
f = Image.open(filename)
is_light = np.mean(np.asarray(f)) > 120
if is_light:
print("off")
l.off()
else:
print("on")
l.on()
os.remove(filename)
except Exception as e:
camera.close()
print(e)
break
sleep(2)
quit()
Now if run the above code in Thonny or mu or even with putty it works without errors but does not work if in /etc/profile
What do I do to either solve the error or atleast how to run the program on startup