Jelajahi Sumber

try/except block to process launch

David 10 tahun lalu
induk
melakukan
91e1827e29
1 mengubah file dengan 17 tambahan dan 12 penghapusan
  1. 17 12
      pmanager/pmanager.py

+ 17 - 12
pmanager/pmanager.py

@@ -134,20 +134,25 @@ class PManager:
     
         log(tolaunch)
         self.log_list[key] = open("/tmp/%s" % key, "w")
-        proc = subprocess.Popen(tolaunch, preexec_fn=os.setsid, stdout=self.log_list[key])
-        #Le doy su propio grupo al subproceso
+        try:
+            proc = subprocess.Popen(tolaunch, preexec_fn=os.setsid, stdout=self.log_list[key])
+            #Le doy su propio grupo al subproceso
+        except Exception as e:
+            log(e)
+            sys.exit(1)
 
         self.p_list[key] = proc
         return proc.pid
 
 if __name__ == "__main__":
-	if len(sys.argv) != 2:
-		print("Usage: ./%s <file.json>" % (sys.argv[0]))
-		sys.exit(1)
-	try:
-		ptable = json.loads(open(sys.argv[1]))
-	except Exception as e:
-		print(e)
-		sys.exit(2)
-	
-	m = PManager(ptable)
+    if len(sys.argv) != 2:
+        print("Usage: ./%s <file.json>" % (sys.argv[0]))
+        sys.exit(1)
+    try:
+        ptable = json.loads(open(sys.argv[1]).read())
+    except Exception as e:
+        print(e)
+        sys.exit(2)
+    
+    print(ptable)
+    m = PManager(ptable)