@@ -439,6 +439,33 @@ <h1 class="title">Module <code>state_signals</code></h1>
439439 self.redis.publish(channel="event-signal-pubsub", message=sig.to_json_str())
440440 self.logger.debug("Initialization successful!")
441441
442+ def initialize_and_wait(
443+ self,
444+ await_sub_count: int,
445+ legal_events: List[str],
446+ tag: str = None,
447+ expected_resps: List[str] = None,
448+ timeout: int = 60,
449+ ) -> int:
450+ """
451+ Calls the SignalExporter's initialize() method, and awaits a specified
452+ number of subscribers. Also includes an optional timeout. Returns 0 if
453+ sub(s) received, 1 if timed-out (or hangs if no timeout).
454+ """
455+ self.initialize(
456+ legal_events=legal_events, tag=tag, expected_resps=expected_resps
457+ )
458+ counter = 0
459+ while len(self.subs) < await_sub_count:
460+ time.sleep(0.1)
461+ counter += 1
462+ if counter >= timeout * 10:
463+ self.logger.error(
464+ f"Timeout after waiting {timeout} seconds for {await_sub_count }subs, got {len(self.subs)}"
465+ )
466+ return 1
467+ return 0
468+
442469 def shutdown(self, tag: str = None) -> None:
443470 """
444471 Shuts down initialization response listener (stops accepting subscribers).
@@ -1135,6 +1162,33 @@ <h3>Methods</h3>
11351162 self.redis.publish(channel="event-signal-pubsub", message=sig.to_json_str())
11361163 self.logger.debug("Initialization successful!")
11371164
1165+ def initialize_and_wait(
1166+ self,
1167+ await_sub_count: int,
1168+ legal_events: List[str],
1169+ tag: str = None,
1170+ expected_resps: List[str] = None,
1171+ timeout: int = 60,
1172+ ) -> int:
1173+ """
1174+ Calls the SignalExporter's initialize() method, and awaits a specified
1175+ number of subscribers. Also includes an optional timeout. Returns 0 if
1176+ sub(s) received, 1 if timed-out (or hangs if no timeout).
1177+ """
1178+ self.initialize(
1179+ legal_events=legal_events, tag=tag, expected_resps=expected_resps
1180+ )
1181+ counter = 0
1182+ while len(self.subs) < await_sub_count:
1183+ time.sleep(0.1)
1184+ counter += 1
1185+ if counter >= timeout * 10:
1186+ self.logger.error(
1187+ f"Timeout after waiting {timeout} seconds for {await_sub_count }subs, got {len(self.subs)}"
1188+ )
1189+ return 1
1190+ return 0
1191+
11381192 def shutdown(self, tag: str = None) -> None:
11391193 """
11401194 Shuts down initialization response listener (stops accepting subscribers).
@@ -1187,6 +1241,45 @@ <h3>Methods</h3>
11871241 self.logger.debug("Initialization successful!")</ code > </ pre >
11881242</ details >
11891243</ dd >
1244+ < dt id ="state_signals.SignalExporter.initialize_and_wait "> < code class ="name flex ">
1245+ < span > def < span class ="ident "> initialize_and_wait</ span > </ span > (< span > self, await_sub_count: int, legal_events: List[str], tag: str = None, expected_resps: List[str] = None, timeout: int = 60) ‑> int</ span >
1246+ </ code > </ dt >
1247+ < dd >
1248+ < div class ="desc "> < p > Calls the SignalExporter's initialize() method, and awaits a specified
1249+ number of subscribers. Also includes an optional timeout. Returns 0 if
1250+ sub(s) received, 1 if timed-out (or hangs if no timeout).</ p > </ div >
1251+ < details class ="source ">
1252+ < summary >
1253+ < span > Expand source code</ span >
1254+ </ summary >
1255+ < pre > < code class ="python "> def initialize_and_wait(
1256+ self,
1257+ await_sub_count: int,
1258+ legal_events: List[str],
1259+ tag: str = None,
1260+ expected_resps: List[str] = None,
1261+ timeout: int = 60,
1262+ ) -> int:
1263+ """
1264+ Calls the SignalExporter's initialize() method, and awaits a specified
1265+ number of subscribers. Also includes an optional timeout. Returns 0 if
1266+ sub(s) received, 1 if timed-out (or hangs if no timeout).
1267+ """
1268+ self.initialize(
1269+ legal_events=legal_events, tag=tag, expected_resps=expected_resps
1270+ )
1271+ counter = 0
1272+ while len(self.subs) < await_sub_count:
1273+ time.sleep(0.1)
1274+ counter += 1
1275+ if counter >= timeout * 10:
1276+ self.logger.error(
1277+ f"Timeout after waiting {timeout} seconds for {await_sub_count }subs, got {len(self.subs)}"
1278+ )
1279+ return 1
1280+ return 0</ code > </ pre >
1281+ </ details >
1282+ </ dd >
11901283< dt id ="state_signals.SignalExporter.publish_signal "> < code class ="name flex ">
11911284< span > def < span class ="ident "> publish_signal</ span > </ span > (< span > self, event: str, sample: int = -1, tag: str = None, metadata: Dict = None, timeout: int = 20) ‑> int</ span >
11921285</ code > </ dt >
@@ -1622,6 +1715,7 @@ <h4><code><a title="state_signals.Signal" href="#state_signals.Signal">Signal</a
16221715< h4 > < code > < a title ="state_signals.SignalExporter " href ="#state_signals.SignalExporter "> SignalExporter</ a > </ code > </ h4 >
16231716< ul class ="">
16241717< li > < code > < a title ="state_signals.SignalExporter.initialize " href ="#state_signals.SignalExporter.initialize "> initialize</ a > </ code > </ li >
1718+ < li > < code > < a title ="state_signals.SignalExporter.initialize_and_wait " href ="#state_signals.SignalExporter.initialize_and_wait "> initialize_and_wait</ a > </ code > </ li >
16251719< li > < code > < a title ="state_signals.SignalExporter.publish_signal " href ="#state_signals.SignalExporter.publish_signal "> publish_signal</ a > </ code > </ li >
16261720< li > < code > < a title ="state_signals.SignalExporter.shutdown " href ="#state_signals.SignalExporter.shutdown "> shutdown</ a > </ code > </ li >
16271721</ ul >
0 commit comments