Explorar o código

Work with time slices instead of number of steps for tasks

Yentl Van Tendeloo %!s(int64=8) %!d(string=hai) anos
pai
achega
28cff5c93a
Modificáronse 1 ficheiros con 11 adicións e 6 borrados
  1. 11 6
      hybrid_server/classes/mvkcontroller.xml

+ 11 - 6
hybrid_server/classes/mvkcontroller.xml

@@ -67,7 +67,6 @@
 
             self.all_failed = False
             self.timeout = False
-            self.init_time = time.time()
 
             self.tasks = set()
             self.input_queue = defaultdict(list)
@@ -217,6 +216,7 @@
                 <state id="execution">
                     <onentry>
                         <script>
+                            #start = time.time()
                             self.outputs = []
                             self.timeout = False
                             if self.tasks:
@@ -231,9 +231,12 @@
                                         self.outputs.append((source, "OK"))
                                         self.all_failed = False
 
-                                    nr_of_steps = 1 if task in self.debugged_tasks else 100
-                                    # Now process for some steps, or until we are again blocked for input
-                                    for x in xrange(nr_of_steps):
+                                    if task in self.debugged_tasks:
+                                        start_time = -float('inf')
+                                    else:
+                                        start_time = time.time()
+                                    # Grant each task some milliseconds of execution
+                                    while (time.time() - start_time &lt; 0.05):
                                         self.execute_modelverse(task, "execute_rule", [])
 
                                         if not self.mvk.success:
@@ -271,14 +274,16 @@
                                     self.tasks.add(name)
                                 self.timeout = self.all_failed
                                 self.all_failed = True
+                            #if time.time() - start > 0.1:
+                            #    print("DIFF: " + str(time.time() - start))
                         </script>
                     </onentry>
 
-                    <transition cond="self.outputs" after="self.sccd_yield()" target="../process_data"/>
+                    <transition cond="self.outputs" target="../process_data"/>
 
                     <transition cond="self.timeout and not self.outputs" after="self.sccd_yield() + 0.10" target="."/>
 
-                    <transition cond="not self.timeout and not self.outputs" after="self.sccd_yield()" target="."/>
+                    <transition cond="not self.timeout and not self.outputs" target="."/>
                 </state>
 
                 <state id="process_data">