Przeglądaj źródła

interrupt simulation if sigterm terminal package is read

Bastien Sevajol 6 lat temu
rodzic
commit
c1c81b7669
3 zmienionych plików z 18 dodań i 1 usunięć
  1. 8 0
      synergine2/core.py
  2. 5 0
      synergine2/terminals.py
  3. 5 1
      synergine2_cocos2d/layer.py

+ 8 - 0
synergine2/core.py Wyświetl plik

76
                 events = []
76
                 events = []
77
                 packages = self.terminal_manager.receive()
77
                 packages = self.terminal_manager.receive()
78
                 for package in packages:
78
                 for package in packages:
79
+                    if package.sigterm:
80
+                        self.logger.info('SIGTERM received from terminal package')
81
+                        self._continue = False
82
+
79
                     events.extend(self.cycle_manager.apply_actions(
83
                     events.extend(self.cycle_manager.apply_actions(
80
                         simulation_actions=package.simulation_actions,
84
                         simulation_actions=package.simulation_actions,
81
                         subject_actions=package.subject_actions,
85
                         subject_actions=package.subject_actions,
102
                 self._end_cycle()
106
                 self._end_cycle()
103
         except KeyboardInterrupt:
107
         except KeyboardInterrupt:
104
             pass  # Just stop while
108
             pass  # Just stop while
109
+
110
+        self.logger.info('Getting out of loop. Terminating.')
105
         self.terminal_manager.stop()
111
         self.terminal_manager.stop()
112
+        self.cycle_manager.stop()
113
+        self.logger.info('Terminated')
106
 
114
 
107
     def _start_cycle(self):
115
     def _start_cycle(self):
108
         time_ = time.time()
116
         time_ = time.time()

+ 5 - 0
synergine2/terminals.py Wyświetl plik

34
             simulation_actions: [tuple]=None,
34
             simulation_actions: [tuple]=None,
35
             subject_actions: [tuple]=None,
35
             subject_actions: [tuple]=None,
36
             is_cycle: bool=False,
36
             is_cycle: bool=False,
37
+            sigterm: bool=False,
37
             *args,
38
             *args,
38
             **kwargs
39
             **kwargs
39
     ):
40
     ):
44
         self.simulation_actions = simulation_actions or []
45
         self.simulation_actions = simulation_actions or []
45
         self.subject_actions = subject_actions or []
46
         self.subject_actions = subject_actions or []
46
         self.is_cycle = is_cycle
47
         self.is_cycle = is_cycle
48
+        self.sigterm = sigterm
47
 
49
 
48
     def repr_debug(self) -> str:
50
     def repr_debug(self) -> str:
49
         subjects = self.subjects or []
51
         subjects = self.subjects or []
55
             simulation_actions=['{}: {}'.format(a.__class__.__name__, p) for a, p in self.simulation_actions],
57
             simulation_actions=['{}: {}'.format(a.__class__.__name__, p) for a, p in self.simulation_actions],
56
             subject_actions=['{}: {}'.format(a.__class__.__name__, p) for a, p in self.subject_actions],
58
             subject_actions=['{}: {}'.format(a.__class__.__name__, p) for a, p in self.subject_actions],
57
             is_cycle=self.is_cycle,
59
             is_cycle=self.is_cycle,
60
+            sigterm=self.sigterm,
58
         ))
61
         ))
59
 
62
 
60
 
63
 
266
                         ))
269
                         ))
267
 
270
 
268
                     packages.append(package)
271
                     packages.append(package)
272
+                    if package.sigterm:
273
+                        return packages
269
             else:
274
             else:
270
                 try:
275
                 try:
271
                     while True:
276
                     while True:

+ 5 - 1
synergine2_cocos2d/layer.py Wyświetl plik

58
         self.subjects_index[actor.subject.id] = actor
58
         self.subjects_index[actor.subject.id] = actor
59
 
59
 
60
 
60
 
61
+class MainScene(cocos.scene.Scene):
62
+    pass
63
+
64
+
61
 class LayerManager(object):
65
 class LayerManager(object):
62
     edit_layer_class = None  # type: typing.Type['EditLayer']
66
     edit_layer_class = None  # type: typing.Type['EditLayer']
63
 
67
 
99
             self.middleware.get_world_height(),
103
             self.middleware.get_world_height(),
100
         )
104
         )
101
 
105
 
102
-        self.main_scene = cocos.scene.Scene()
106
+        self.main_scene = MainScene()
103
         self.scrolling_manager = ScrollingManager()
107
         self.scrolling_manager = ScrollingManager()
104
 
108
 
105
         self.main_layer = MainLayer(
109
         self.main_layer = MainLayer(