oljohan
Posts: 3
Joined: Wed Jun 15, 2016 7:25 pm

Stop PiCamera preview

Tue Jun 21, 2016 6:53 pm

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

rosecahill
Posts: 4
Joined: Thu Jun 16, 2016 1:33 pm

Re: Stop PiCamera preview

Tue Jun 21, 2016 8:03 pm


oljohan
Posts: 3
Joined: Wed Jun 15, 2016 7:25 pm

Re: Stop PiCamera preview

Tue Jun 21, 2016 8:21 pm

That's the site where I learned to use the camera, bit cannot find anything about how to exit the script :(

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: Stop PiCamera preview

Tue Jun 21, 2016 9:43 pm

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

Damit84
Posts: 3
Joined: Tue Jun 21, 2016 5:48 am

Re: Stop PiCamera preview

Wed Jun 22, 2016 5:54 am

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()

MarcScott
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 81
Joined: Sat Aug 08, 2015 11:30 am

Re: Stop PiCamera preview

Wed Jun 22, 2016 7:07 am

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

Code: Select all

pkill python3
to end the program.

theeRichard
Posts: 1
Joined: Mon Apr 02, 2018 2:05 pm

Re: Stop PiCamera preview

Mon Apr 02, 2018 2:18 pm

@MarcScott

I created an account just to say thank you! Very much appreciated!

andalus
Posts: 24
Joined: Fri Sep 14, 2018 11:22 pm

Re: Stop PiCamera preview

Sun Oct 21, 2018 2:31 pm

MarcScott wrote:
Wed Jun 22, 2016 7:07 am
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

Code: Select all

pkill python3
to end the program.
Thank you for the good answer.
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).

Return to “Python”