import input_utils
import string_utils
+ now: datetime.datetime = datetime_utils.now_pacific()
+ info = f"""Timestamp: {datetime_utils.datetime_to_string(now)}
+Model params: {params}
+Training examples: {num_examples}
+Training set score: {training_score:.2f}%
+Testing set score: {test_score:.2f}%"""
+ print(f'\n{info}\n')
if (
(self.spec.persist_percentage_threshold is not None and
test_score > self.spec.persist_percentage_threshold)
print(msg)
logger.info(msg)
model_info_filename = f"{self.spec.basename}_model_info.txt"
- now: datetime.datetime = datetime_utils.now_pacific()
- info = f"""Timestamp: {datetime_utils.datetime_to_string(now)}
-Model params: {params}
-Training examples: {num_examples}
-Training set score: {training_score:.2f}%
-Testing set score: {test_score:.2f}%"""
with open(model_info_filename, "w") as f:
f.write(info)
msg = f"Wrote {model_info_filename}:"
import datetime
import logging
import time
+import threading
from typing import Dict, Optional
import pytz
logger.debug('pace_maker noticed event; shutting down')
return
self.heartbeat()
- logger.debug(f'page_maker is sleeping for {self.sleep_delay}s')
+ logger.debug(f'pace_maker is sleeping for {self.sleep_delay}s')
time.sleep(self.sleep_delay)
def __init__(
self.should_terminate.set()
self.updater_thread.join()
logger.debug('Background thread terminated.')
+
+
+class WaitableAutomaticStateTracker(AutomaticStateTracker):
+
+ def __init__(
+ self,
+ update_ids_to_update_secs: Dict[str, float],
+ *,
+ override_sleep_delay: Optional[float] = None,
+ ) -> None:
+ self._something_changed = threading.Event()
+ super().__init__(update_ids_to_update_secs,
+ override_sleep_delay=override_sleep_delay)
+
+ def something_changed(self):
+ self._something_changed.set()
+
+ def did_something_change(self) -> bool:
+ return self._something_changed.is_set()
+
+ def reset(self):
+ self._something_changed.clear()
+
+ def wait(self,
+ *,
+ timeout=None):
+ return self._something_changed.wait(
+ timeout=timeout
+ )