From b42f6687f77c2ae99f4b528e26351989fe2d772e Mon Sep 17 00:00:00 2001 From: acastro Date: Mon, 21 Jan 2019 16:45:54 +0000 Subject: [PATCH] adding process kill cases, to prevent guru from playing at the same time as announcements.py --- announcements.py | 13 +++++++++++++ guru-pirate.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/announcements.py b/announcements.py index 470c14a..3d51048 100755 --- a/announcements.py +++ b/announcements.py @@ -6,6 +6,19 @@ from LEDfunctions import * # this script plays the content of the announcer (from json file) +import subprocess +# is the guru running? +try: + pirate_pid = subprocess.check_output( + ["pgrep", "-f", "guru-pirate.py"] + ) + print("guru pirate running:",pirate_pid) + subprocess.call(["kill", pirate_pid.replace("\n","")]) +except: + print("guru-pirate is not running") +sleep(4) + + # when characters speak the LEDs light up and perform effects def vu_2_leds(color): while True: diff --git a/guru-pirate.py b/guru-pirate.py index b729eff..1572ce6 100755 --- a/guru-pirate.py +++ b/guru-pirate.py @@ -7,7 +7,20 @@ import json, random, os, subprocess from pprint import pprint from time import sleep from LEDfunctions import * +import sys +import subprocess +# is the announcements.py running? +try: # try: if no error - the process is running. + # therefore exit() + ann_pid = subprocess.check_output(["pgrep", "-f", "announcements.py"]) + print("announcements.py ARE running. Will stop here", ann_pid) + +except: + print("announcements.py are not running. Will run guru") + +if 'ann_pid' in vars() or 'ann_pid' in globals(): + sys.exit(1) # when characters speak the LEDs light up and perform effects def vu_2_leds(color):