Browse Source

Minor optimization of pop_requests

Yentl Van Tendeloo 7 years ago
parent
commit
83ab2b3257

+ 1 - 1
kernel/modelverse_kernel/main.py

@@ -46,7 +46,7 @@ class ModelverseKernel(object):
             # Create the generator for the function to execute
             # Create the generator for the function to execute
             self.request_handlers[taskname][operation] = RequestHandler()
             self.request_handlers[taskname][operation] = RequestHandler()
         handler = self.request_handlers[taskname][operation]
         handler = self.request_handlers[taskname][operation]
-        if not handler.is_active():
+        if len(handler.generator_stack) == 0:
             handler.push_generator(getattr(self, operation)(taskname, *params))
             handler.push_generator(getattr(self, operation)(taskname, *params))
 
 
         return handler.handle_request(reply)
         return handler.handle_request(reply)

+ 7 - 9
kernel/modelverse_kernel/request_handler.py

@@ -37,10 +37,6 @@ class RequestHandler(object):
             'SLEEP' : self.execute_sleep,
             'SLEEP' : self.execute_sleep,
         }
         }
 
 
-    def is_active(self):
-        """Tests if this request handler has a top-of-stack generator."""
-        return len(self.generator_stack) > 0
-
     def handle_request(self, reply):
     def handle_request(self, reply):
         """Replies to a request from the top-of-stack generator, and returns a new request."""
         """Replies to a request from the top-of-stack generator, and returns a new request."""
         if not self.generator_stack:
         if not self.generator_stack:
@@ -64,10 +60,10 @@ class RequestHandler(object):
                     gen["pending_requests"] = gen["generator"].send(gen["replies"])
                     gen["pending_requests"] = gen["generator"].send(gen["replies"])
                     gen["finished_requests"] = False
                     gen["finished_requests"] = False
                     gen["replies"] = None
                     gen["replies"] = None
-                return self.pop_requests()
+                ret = self.pop_requests()
+                if ret[0]:
+                    return ret[1]
 
 
-            except KnownRequestHandled:
-                pass
             except StopIteration:
             except StopIteration:
                 # Done, so remove the generator
                 # Done, so remove the generator
                 del self.generator_stack[-1]
                 del self.generator_stack[-1]
@@ -123,7 +119,8 @@ class RequestHandler(object):
 
 
                 # Handle the request.
                 # Handle the request.
                 self.handlers[elem[0]](elem[1])
                 self.handlers[elem[0]](elem[1])
-                raise KnownRequestHandled()
+                return (False, None)
+                #raise KnownRequestHandled()
             else:
             else:
                 for i, elem in enumerate(requests):
                 for i, elem in enumerate(requests):
                     if elem[0] in self.handlers:
                     if elem[0] in self.handlers:
@@ -135,7 +132,8 @@ class RequestHandler(object):
         # We couldn't find a known request in the batch of requests, so we might as well
         # We couldn't find a known request in the batch of requests, so we might as well
         # handle them all at once then.
         # handle them all at once then.
         self.generator_stack[-1]["finished_requests"] = True
         self.generator_stack[-1]["finished_requests"] = True
-        return requests
+        #return requests
+        return (True, requests)
 
 
     def execute_call(self, request_args):
     def execute_call(self, request_args):
         """Executes a CALL-request with the given argument list."""
         """Executes a CALL-request with the given argument list."""

+ 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:   Fri Apr 27 10:19:38 2018
+Date:   Fri Apr 27 10:46:54 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server