Dirk Alders 4 lat temu
rodzic
commit
23a502dc31
3 zmienionych plików z 7626 dodań i 5823 usunięć
  1. 13
    8
      __init__.py
  2. 7613
    5815
      _testresults_/unittest.json
  3. BIN
      _testresults_/unittest.pdf

+ 13
- 8
__init__.py Wyświetl plik

@@ -72,6 +72,7 @@ class state_machine(object):
72 72
         self.__state_change_callbacks__ = {}
73 73
         self.__log_lvl__ = log_lvl
74 74
         self.__set_state__(default_state, '__init__')
75
+        self.__callback_id__ = 0
75 76
         for key in kwargs:
76 77
             setattr(self, key, kwargs.get(key))
77 78
 
@@ -91,7 +92,8 @@ class state_machine(object):
91 92
             self.__state_change_callbacks__[state] = {}
92 93
         if condition not in self.__state_change_callbacks__[state]:
93 94
             self.__state_change_callbacks__[state][condition] = []
94
-        self.__state_change_callbacks__[state][condition].append((callback, args, kwargs))
95
+        self.__state_change_callbacks__[state][condition].append((self.__callback_id__, callback, args, kwargs))
96
+        self.__callback_id__ += 1
95 97
 
96 98
     def this_state(self):
97 99
         """
@@ -182,13 +184,16 @@ class state_machine(object):
182 184
         self.__last_transition_condition__ = condition
183 185
         self.__time_stamp_state_change__ = timestamp
184 186
         self.__conditions_start_time__ = {}
185
-        for callback, args, kwargs in self.__state_change_callbacks__.get(None, {}).get(None, []):
186
-            callback(*args, **kwargs)
187
-        for callback, args, kwargs in self.__state_change_callbacks__.get(target_state, {}).get(None, []):
188
-            callback(*args, **kwargs)
189
-        for callback, args, kwargs in self.__state_change_callbacks__.get(None, {}).get(condition, []):
190
-            callback(*args, **kwargs)
191
-        for callback, args, kwargs in self.__state_change_callbacks__.get(target_state, {}).get(condition, []):
187
+        # Callback collect
188
+        this_state_change_callbacks = self.__state_change_callbacks__.get(None, {}).get(None, [])
189
+        this_state_change_callbacks.extend(self.__state_change_callbacks__.get(target_state, {}).get(None, []))
190
+        this_state_change_callbacks.extend(self.__state_change_callbacks__.get(None, {}).get(condition, []))
191
+        this_state_change_callbacks.extend(self.__state_change_callbacks__.get(target_state, {}).get(condition, []))
192
+        # Callback sorting
193
+        this_state_change_callbacks.sort()
194
+        # Callback execution
195
+        for cid, callback, args, kwargs in this_state_change_callbacks:
196
+            logger.debug('Executing callback %d - %s.%s', cid, callback.__module__, callback.__name__)
192 197
             callback(*args, **kwargs)
193 198
 
194 199
     def work(self):

+ 7613
- 5815
_testresults_/unittest.json
Plik diff jest za duży
Wyświetl plik


BIN
_testresults_/unittest.pdf Wyświetl plik


Ładowanie…
Anuluj
Zapisz