mavpi
Posts: 16
Joined: Fri Dec 13, 2013 1:49 pm

Running the Camera board as a background process

Sun Jan 05, 2014 5:41 pm

I'm trying to make a camera mount that can be remotely controlled. I'm using servo blaster to control the servo and the Camera board. When i initialize the camera though python, it waits for the camera to finish transmitting before proceeding to the next code. How can I make the script move on the the next part as soon as the camera is initialized and not wait for the camera process to finish. The whole program can be found here. http://pastebin.com/zKwnqEjr

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Running the Camera board as a background process

Sun Jan 05, 2014 6:01 pm

If execute a command or shell script with & appended it should run as a background process.
Whether this method would work with your python code I cannot really say.

Richard S.

mavpi
Posts: 16
Joined: Fri Dec 13, 2013 1:49 pm

Re: Running the Camera board as a background process

Sun Jan 05, 2014 6:06 pm

redhawk wrote:If execute a command or shell script with & appended it should run as a background process.
Whether this method would work with your python code I cannot really say.

Richard S.
Where would I append the '&'? I'm new to python, so can you please give me an example?

gordon77
Posts: 5134
Joined: Sun Aug 05, 2012 3:12 pm

Re: Running the Camera board as a background process

Sun Jan 05, 2014 7:09 pm

I use subprocess to run in the background taking images into /run/shm/test.jpg.

eg

Code: Select all

if use_RPiwebcam == 1:
   try:
      os.remove('/run/shm/test.jpg')
   except OSError:
      pass
   rpistr = "raspistill -o /run/shm/test.jpg -co " + str(rpico) + " -br " + str(rpibr)
   rpistr = rpistr + " -t " + str(rpit) + " -tl 0 -ex " + rpiex
   rpistr = rpistr + " -ISO " + str(rpiISO)
   rpistr = rpistr + " -n -sa " + str(rpisa)
   rpistr = rpistr + " -w " + str(w) + " -h " + str(h)
   p=subprocess.Popen(rpistr,shell=True, preexec_fn=os.setsid)
If you need to stop the process use

Code: Select all

os.killpg(p.pid, signal.SIGTERM)
and then you can restart it

mavpi
Posts: 16
Joined: Fri Dec 13, 2013 1:49 pm

Re: Running the Camera board as a background process

Sun Jan 05, 2014 7:14 pm

I used redhawk's method and it worked fine.

Return to “Python”