How to run 2 sripts at the same time?

Goodevening,

Does anybody have an idea how to run these 2 scripts at the same time?

What would be the best way to?

I have tried to activate the 2 scripts with a bashscript, but this gave some weird results.

The goal is that the BBB completes the grafcet and has a blinking green LED to show it’s running.

I know I could just paste running_green under grafcet, but then the timing of the blinking would not be correct.

Here are the 2 python scripts:
Grafcet.py

#!/usr/bin/python

import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup(“P8_12”, GPIO.OUT)
GPIO.setup(“P8_14”, GPIO.OUT)
GPIO.setup(“P8_16”, GPIO.OUT)
GPIO.setup(“P8_18”, GPIO.OUT)
GPIO.setup(“P8_11”, GPIO.IN)
GPIO.setup(“P8_13”, GPIO.IN)
GPIO.setup(“P8_15”, GPIO.IN)
GPIO.setup(“P8_17”, GPIO.IN)
GPIO.setup(“P8_19”, GPIO.IN)

X = 0

while True:

stap 1

if GPIO.input(“P8_11”) and X == 0:
GPIO.output(“P8_12”, GPIO.HIGH)
X += 1
print"Step 1: Boiling ingredients"

stap 2

elif GPIO.input(“P8_13”) and X == 1:
GPIO.output(“P8_14”, GPIO.HIGH)
GPIO.output(“P8_12”, GPIO.LOW)
X += 1
print"Step 2: Add yeast and sugar"
elif GPIO.input(“P8_15”) and X == 2:
GPIO.output(“P8_16”, GPIO.HIGH)
GPIO.output(“P8_14”, GPIO.LOW)
X += 1
print"Step 3: fermenting for 6 weeks"

stap 4

elif GPIO.input(“P8_17”) and X == 3:
GPIO.output(“P8_16”, GPIO.LOW)
X = 0
print"End of cycle, beer is ready"

noodstop NC

elif GPIO.input(“P8_19”) == False:
X = 5
print"Emergency button has been activated!"
time.sleep(.1)

running_green.py

#!/usr/bin/python

import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup(“P8_18”, GPIO.OUT)

while True:
time.sleep(.5)
GPIO.output(“P8_18”, GPIO.HIGH)
time.sleep(.5)
GPIO.output(“P8_18”, GPIO.LOW)

Take time.time modulo 1 and not sleep.time, and paste it into one program
eg:

Just run the script in background adding the & in command line.
http://www.thegeekstuff.com/2010/05/unix-background-job/

Thanks Leonard, using the ampersand in a bash script worked.

#!/bin/bash

python grafcet.py &
python running_green.py &

I could only kill the pythons scripts by using the “ps” command (to see the running processes) and “kill” (to stop a process).

The command “jobs” doesn’t seem to work on Angstrom, is this correct?

#!/bin/bash

python grafcet.py &
python running_green.py &

Correction:

Jobs, fg and bg work on Angstrom.

But when you start the 2 scripts in a bash command:

#!/bin/bash

python grafcet.py &
python running_green.py &

Jobs cannot catch them.

You can only catch them with jobs, if you start each python script seperately and then use crtl-Z and bg to put the task in the background.

When you do it like so, jobs can see these scripts.

I guess I will have to use threads to start the 2 scripts at the same time and still have control over them.