Hi!
I've had some problem when using the PiCamera in python. Sometimes, when something happens in a loop and the Camera starts its preview, it is impossible to exit the script. I have to unplug the power cable which ones resulting in that a file in the sd-card was damaged so that I had to install Rasbian all over again... Anyone knows how to stop a script when the PiCamera has started its preview or knows something to write in the code (like a try-statement) to be able to exit the script?
Johan
-
- Posts: 4
- Joined: Thu Jun 16, 2016 1:33 pm
Re: Stop PiCamera preview
It might be helpful to look over https://www.raspberrypi.org/learning/ge ... worksheet/
Re: Stop PiCamera preview
That's the site where I learned to use the camera, bit cannot find anything about how to exit the script 

-
- Posts: 690
- Joined: Tue Jun 16, 2015 6:01 am
Re: Stop PiCamera preview
Typically a CTRL-D will exit a Py script. However, not knowing your setup, can you post your code and use the Code blocks for us?
Account Inactive
Re: Stop PiCamera preview
Had a similar problem with the camera. I forgot an adequate try / finally block with the camera_preview shutting off in the finally block. I resulted in a ongoing preview when an exception occured.
Code: Select all
camera = picamera.PiCamera()
try:
camera.start_preview()
#DoCameraRelatedStuff
finally:
camera.stop_preview()
camera.close()
-
- Raspberry Pi Foundation Employee & Forum Moderator
- Posts: 83
- Joined: Sat Aug 08, 2015 11:30 am
Re: Stop PiCamera preview
I've frequently had problems with this, compounded by random clicking meaning IDLE no longer has focus.
Luckily if you are on the latest version of Raspbian, there's a simple solution.
Hold down ctrl+alt+t which will open up a terminal that has focus, although hidden behind the preview.
Then blindly type to end the program.
Luckily if you are on the latest version of Raspbian, there's a simple solution.
Hold down ctrl+alt+t which will open up a terminal that has focus, although hidden behind the preview.
Then blindly type
Code: Select all
pkill python3
-
- Posts: 1
- Joined: Mon Apr 02, 2018 2:05 pm
Re: Stop PiCamera preview
@MarcScott
I created an account just to say thank you! Very much appreciated!
I created an account just to say thank you! Very much appreciated!
Re: Stop PiCamera preview
Thank you for the good answer.MarcScott wrote: ↑Wed Jun 22, 2016 7:07 amI've frequently had problems with this, compounded by random clicking meaning IDLE no longer has focus.
Luckily if you are on the latest version of Raspbian, there's a simple solution.
Hold down ctrl+alt+t which will open up a terminal that has focus, although hidden behind the preview.
Then blindly typeto end the program.Code: Select all
pkill python3
One can also login from SSH and issue pkill python as well (Or may look into the process ID and kill it if multiple python programs are running).
Re: Stop PiCamera preview
Thanks your solution worked.MarcScott wrote: ↑Wed Jun 22, 2016 7:07 amI've frequently had problems with this, compounded by random clicking meaning IDLE no longer has focus.
Luckily if you are on the latest version of Raspbian, there's a simple solution.
Hold down ctrl+alt+t which will open up a terminal that has focus, although hidden behind the preview.
Then blindly typeto end the program.Code: Select all
pkill python3