Parcourir la source

Change nicer termination behaviour without tons of stacktraces

Yentl Van Tendeloo il y a 7 ans
Parent
commit
5fac9c6fff

+ 2 - 0
hybrid_server/classes/task.xml

@@ -40,6 +40,8 @@
                 return (0.0, False)
                 return (0.0, False)
             except SleepKernel as e:
             except SleepKernel as e:
                 return (e.timeout, e.interruptable)
                 return (e.timeout, e.interruptable)
+            except KeyboardInterrupt:
+                raise
             except:
             except:
                 import traceback
                 import traceback
                 print(traceback.format_exc())
                 print(traceback.format_exc())

+ 3 - 5
scripts/run_local_modelverse.py

@@ -27,11 +27,6 @@ try:
         service = subprocess.Popen([sys.executable, service_path, "127.0.0.1:%s" % port])
         service = subprocess.Popen([sys.executable, service_path, "127.0.0.1:%s" % port])
         services.append(service)
         services.append(service)
 
 
-    #os.chdir("hybrid_server")
-    #program_to_execute = [sys.executable, "run_mvk_server.py", port]
-    #server = subprocess.Popen(program_to_execute)
-    #server.wait()
-
     sys.path.append("hybrid_server")
     sys.path.append("hybrid_server")
     sys.path.append(".")
     sys.path.append(".")
     os.chdir("hybrid_server")
     os.chdir("hybrid_server")
@@ -46,6 +41,9 @@ try:
     socket2event.boot_translation_service(controller)
     socket2event.boot_translation_service(controller)
     controller.start()
     controller.start()
 
 
+except KeyboardInterrupt:
+    pass
+
 finally:
 finally:
     # Terminate all services as well
     # Terminate all services as well
     for service in services:
     for service in services:

+ 13 - 10
services/DEVS/main.py

@@ -13,9 +13,6 @@ from ps_model import Root
 
 
 import threading, time
 import threading, time
 
 
-init(sys.argv[1])
-login("pypdevs_service", "my_password")
-
 def pypdevs_service(port):
 def pypdevs_service(port):
     exec(service_get(port), globals(), {})
     exec(service_get(port), globals(), {})
 
 
@@ -56,11 +53,17 @@ def pypdevs_service(port):
 
 
     controller.start()
     controller.start()
 
 
-service_register("pypdevs_simulator", pypdevs_service)
-
 try:
 try:
-    while True:
-        # Stay active, as we shouldn't exit while the service is running!
-        time.sleep(1)
-finally:
-    service_stop()
+    init(sys.argv[1])
+    login("pypdevs_service", "my_password")
+
+    service_register("pypdevs_simulator", pypdevs_service)
+
+    try:
+        while True:
+            # Stay active, as we shouldn't exit while the service is running!
+            time.sleep(1)
+    finally:
+        service_stop()
+except KeyboardInterrupt:
+    pass

+ 20 - 16
services/HUTN/main.py

@@ -8,8 +8,6 @@ from modelverse import *
 import os
 import os
 
 
 import time
 import time
-init(sys.argv[1])
-login("HUTN", "HUTN")
 
 
 def clean_code(code):
 def clean_code(code):
     if code == "":
     if code == "":
@@ -74,18 +72,24 @@ def compile_service(port):
         service_set(port, str(e))
         service_set(port, str(e))
         raise
         raise
 
 
-service_register("compiler", compile_service)
-
 try:
 try:
-    if sys.version_info[0] < 3:
-        while raw_input() != "STOP":
-            pass
-    else:
-        while input() != "STOP":
-            pass
-except EOFError:
-    import time
-    while 1:
-        time.sleep(1.0)
-finally:
-    service_stop()
+    init(sys.argv[1])
+    login("HUTN", "HUTN")
+
+    service_register("compiler", compile_service)
+
+    try:
+        if sys.version_info[0] < 3:
+            while raw_input() != "STOP":
+                pass
+        else:
+            while input() != "STOP":
+                pass
+    except EOFError:
+        import time
+        while 1:
+            time.sleep(1.0)
+    finally:
+        service_stop()
+except KeyboardInterrupt:
+    pass

+ 20 - 17
services/JSON/main.py

@@ -5,9 +5,6 @@ import os
 import json
 import json
 
 
 import time
 import time
-init(sys.argv[1])
-login("JSON", "JSON")
-
 def json_service(port):
 def json_service(port):
     def print_out_json(data):
     def print_out_json(data):
         if isinstance(data, dict):
         if isinstance(data, dict):
@@ -74,19 +71,25 @@ def json_service(port):
         service_set(port, str(e))
         service_set(port, str(e))
         raise
         raise
 
 
-service_register("JSON", json_service)
-
 try:
 try:
-    if sys.version_info[0] < 3:
-        while raw_input() != "STOP":
-            pass
-    else:
-        while input() != "STOP":
-            pass
+    init(sys.argv[1])
+    login("JSON", "JSON")
+
+    service_register("JSON", json_service)
+
+    try:
+        if sys.version_info[0] < 3:
+            while raw_input() != "STOP":
+                pass
+        else:
+            while input() != "STOP":
+                pass
 
 
-except EOFError:
-    import time
-    while 1:
-        time.sleep(1.0)
-finally:
-    service_stop()
+    except EOFError:
+        import time
+        while 1:
+            time.sleep(1.0)
+    finally:
+        service_stop()
+except KeyboardInterrupt:
+    pass

+ 18 - 13
services/LoLA/main.py

@@ -6,9 +6,6 @@ from modelverse import *
 from subprocess import Popen, PIPE
 from subprocess import Popen, PIPE
 import json
 import json
 
 
-init(sys.argv[1])
-login("test_service", "my_password")
-
 def lola_service(port):
 def lola_service(port):
     json_input = service_get(port)
     json_input = service_get(port)
     input_data = json.loads(json_input)
     input_data = json.loads(json_input)
@@ -31,15 +28,23 @@ def lola_service(port):
     service_set(port, result['analysis']['result'])
     service_set(port, result['analysis']['result'])
     service_set(port, path.rstrip(','))
     service_set(port, path.rstrip(','))
 
 
-service_register("lola", lola_service)
+try:
+    init(sys.argv[1])
+    login("test_service", "my_password")
+
+    service_register("lola", lola_service)
 
 
-if sys.version_info[0] < 3:
-    while raw_input() != "STOP":
-        # Stay active, as we shouldn't exit while the service is running!
-        pass
-else:
-    while input() != "STOP":
-        # Stay active, as we shouldn't exit while the service is running!
-        pass
+    try:
+        if sys.version_info[0] < 3:
+            while raw_input() != "STOP":
+                # Stay active, as we shouldn't exit while the service is running!
+                pass
+        else:
+            while input() != "STOP":
+                # Stay active, as we shouldn't exit while the service is running!
+                pass
 
 
-service_stop()
+    finally:
+        service_stop()
+except KeyboardInterrupt:
+    pass

+ 20 - 17
services/files/main.py

@@ -6,9 +6,6 @@ import json
 
 
 import time
 import time
 import traceback
 import traceback
-time.sleep(1)
-init(sys.argv[1])
-login("file", "file")
 
 
 def file_service(port):
 def file_service(port):
     filename = service_get(port)
     filename = service_get(port)
@@ -21,18 +18,24 @@ def file_service(port):
         service_set(port, "Failure: " + traceback.format_exc())
         service_set(port, "Failure: " + traceback.format_exc())
         raise
         raise
 
 
-service_register("files", file_service)
-
 try:
 try:
-    if sys.version_info[0] < 3:
-        while raw_input() != "STOP":
-            pass
-    else:
-        while input() != "STOP":
-            pass
-except EOFError:
-    import time
-    while 1:
-        time.sleep(1.0)
-finally:
-    service_stop()
+    init(sys.argv[1])
+    login("file", "file")
+
+    service_register("files", file_service)
+
+    try:
+        if sys.version_info[0] < 3:
+            while raw_input() != "STOP":
+                pass
+        else:
+            while input() != "STOP":
+                pass
+    except EOFError:
+        import time
+        while 1:
+            time.sleep(1.0)
+    finally:
+        service_stop()
+except KeyboardInterrupt:
+    pass

+ 2 - 0
unit/test_all.py

@@ -94,7 +94,9 @@ class TestModelverse(unittest.TestCase):
     @classmethod
     @classmethod
     def tearDownClass(self):
     def tearDownClass(self):
         try:
         try:
+            print("Killing " + str(TestModelverse.proc))
             kill(TestModelverse.proc)
             kill(TestModelverse.proc)
+            print("Killed " + str(TestModelverse.proc))
         except:
         except:
             print("Got exception during teardown.")
             print("Got exception during teardown.")
 
 

+ 1 - 1
unit/utils.py

@@ -59,7 +59,7 @@ def child_kill(pid):
     subprocess.call(["pkill", "-P", "%i" % pid])
     subprocess.call(["pkill", "-P", "%i" % pid])
     start = time.time()
     start = time.time()
     with open(os.devnull, 'w') as null:
     with open(os.devnull, 'w') as null:
-        while subprocess.call(["pgrep", "-P", "%i" % pid], stdout=null) != 1:
+        while subprocess.call(["pgrep", "-P", "%i" % pid], stdout=null) > 1:
             time.sleep(0.1)
             time.sleep(0.1)
             if time.time() > start + 4:
             if time.time() > start + 4:
                 subprocess.call(["pkill", "-9", "-P", "%i" % pid])
                 subprocess.call(["pkill", "-9", "-P", "%i" % pid])

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Tue Apr 24 17:47:15 2018
+Date:   Wed Apr 25 07:24:20 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server