0

I'm hoping you can help (as always). I'm making a photobooth and in short have a Python script to control the light (switches on for 30 seconds) and another to take 4 photos for the photobooth. I need to run the light script followed by the camera script 5 seconds later. I'm sure this is easy, but can't work it out. Here's what I've tried:

I'm not even sure if this is correct for the Raspberry Pi, but this is what I've tried inc. variations:

import threading
import time
def light():
    while time.time() <= start_time:
        pass
    threading.Thread(target="sudo python /home/pi/python/light30.py").start()
def camera():
    while time.time() <= start_time:
        pass
    threading.Thread(target="sudo python /home/pi/python/camtest.py").start()
start_time=time.time()+5
threading.Thread(target=light).start()
threading.Thread(target=camera).start()

Any help you can provide would be great, as I'm sure im being an idiot.

3
  • Thread target argument should be callable object, not string. Commented Jul 20, 2015 at 18:35
  • I wish I had the knowledge as you do Lukasz. How would I do this - I'm a relative n00b Commented Jul 20, 2015 at 18:44
  • why do you need to run the scripts with sudo? Commented Jul 20, 2015 at 18:58

1 Answer 1

1

as mentioned in the comments threading expects to run python code ... not a python file ... you can just use subprocess to accomplish that you want

import subprocess
import time

lights_proc = subprocess.Popen(["/usr/bin/python","/home/pi/python/light30.py"])
time.sleep(5) # sleep for 5 seconds
print subprocess.Popen(["/usr/bin/python","/home/pi/python/camtest.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()

the communicate call at the end just makes it block and wait for camtest.py to complete before exiting this script (as well as getting the output from the script)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much Joran, that's what I couldn't get my head around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.