I'm quite new to python.
I'm writing an application that publishes JSON packets on a mosquito broker. The application spawns also a thread that subscribes to another topic of the broker and depending on the received message it has to start or stop a bash script.
def on_message(client, userdata, msg):
if (str(msg.payload)=="START_1"):
proc=subprocess.Popen("./rec", shell=True)
elif(str(msg.payload)=="START_2"):
proc=subprocess.Popen("./send", shell=True)
elif(str(msg.payload)=="STOP_1"):
subprocess.Popen("kill", "-9", "$proc.pid", shell=True)
elif(str(msg.payload)=="STOP_2"):
subprocess.call("kill", "-9", "$proc.pid", shell=True)
class FW_video (Thread):
def __init__(self, nome):
import paho.mqtt.client as mqtt
from threading import Thread
import time
import json
import random
import sys
import threading
import ctypes
import subprocess
Thread.__init__(self)
self.nome = nome
def run(self):
print ("Thread '" + self.name + "' avviato")
client=mqtt.Client()
client.username_pw_set(username="--------", password="----------")
client.connect("127.0.0.1",1883)
client.subscribe("prova")
client.on_message=on_message
client.loop_forever()
client.disconnect()
print ("Thread '" + self.nome + "' terminato")
thread1 = FW_video("Thread#1")
thread1.start()
The bash script starts correctly but it doesn't stop when receives one of the two string (STOP_1 or STOP_2 )
Could someone, please, give me a hint. Thank you in advance