I am trying to start the
picamera process on the main thread and pass it as an argument to a new process, where I would take photos with the camera while the main process runs. However, the camera does not produce any images when operated in the other process, and the code hangs at
p1.join(). Here is the code.
import time from multiprocessing import Process import picamera def snapPhoto(camera): for i in range(3): camera.capture('threaded_photo_' + str(i) + '.jpg') # Tried to use video port with no luck #camera.capture('threaded_photo_' + str(i) + '.jpg', use_video_port=True) def runCameraPreview(): #for i in range(3): with picamera.PiCamera() as camera: # Get the camera ready time.sleep(2) print("Starting process") # try image capture in a thread p1 = Process(target=snapPhoto, args=(camera,)) p1. start() # Do any processing print("Waiting") p1.join() # Wait for the process to return runCameraPreview()
I simply create the camera object and pass it as an argument (one object in
tuple) to the
Process. The code then waits for the images to be taken. However, it never takes the images. How can I make the camera to take photos in a separate thread?
Edit: I will need the camera object in the main thread so initializing the camera on the side process in not an option.
PS. You have to terminate the code by force, it will not exit. Moreover, a process using the camera resource will be open in the background until
killall python is executed.