1

So I was trying out this exact same script in this answer https://raspberrypi.stackexchange.com/a/46513 but when I tried to run it (for the second or third time) it gave me this exception:

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/dist-packages/gpiozero/mixins.py", line 509, in fill
self.parent._fire_events()
File "/usr/lib/python2.7/dist-packages/gpiozero/mixins.py", line 327, in _fire_events
self._fire_deactivated()
File "/usr/lib/python2.7/dist-packages/gpiozero/mixins.py", line 306, in _fire_deactivated
self.when_deactivated()
File "PIRscript.py", line 24, in finish_video
camera.stop_recording()
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 1193, in stop_recording
'port %d' % splitter_port)
PiCameraNotRecording: There is no recording in progress on port 1

I rebooted my pi and tried starting up the script again, but I keep getting this error. This seems like it's because I don't close the camera anywhere, but I need to know

  1. how do I handle this exception now i.e. how do I make this error go away?
  2. how do I change my code to make it close the camera safely?
0

While I was never able to figure out how to integrate a safe camera-closing solution into that script, I ended up using a workaround which uses the functions pir.wait_for_motion() and pir.wait_for_no_motion() and the code looks something like this:

pir.wait_for_motion()
camera = PiCamera()
camera.start_preview()
camera.start_recording(video_name)
pir.wait_for_no_motion()
camera.stop_recording()
camera.stop_preview()
camera.close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.