Kaynağa Gözat

fix typo and kill process if it doesnt exit in 100ms

David 8 yıl önce
ebeveyn
işleme
7291f696ec
1 değiştirilmiş dosya ile 9 ekleme ve 3 silme
  1. 9 3
      camera1/handle-cam2.py

+ 9 - 3
camera1/handle-cam2.py

@@ -19,6 +19,7 @@ def on_connect(client, userdata, flags, rc):
 
 # The callback for when a PUBLISH message is received from the server.
 def on_message(client, userdata, msg):
+    global p
     print(msg.topic+" "+str(msg.payload))
     if msg.topic == "video/cam2/preview":
         try:
@@ -26,12 +27,17 @@ def on_message(client, userdata, msg):
         except Exception as e:
             print(e)
             return
-        if run and p is None:
+        if run == 1 and p is None:
             print("Starting")
-            p = subprocess.Popen(["/home/curso/code/snowmix/camera1/play-cam2.sh"]
-        if p is not None and not run:
+            p = subprocess.Popen(["/home/curso/code/snowmix/camera1/play-cam2.sh"])
+        if (p is not None and run == 0):
             print("Stopping")
             p.terminate()
+            sleep(0.1)
+            if p is not None:
+                p.kill()
+                sleep(0.1)
+                p = None
 
 
 client = mqtt.Client()