def _current():
     try:
         return virtual_memory().percent, cpu_percent()
     except KeyError:
         # for some reason there's a KeyError: ('psutil',) in psutil
         return 0, 0
     except Exception as e:
         simple_logger.exception(e)
         return 0, 0
Пример #2
0
 def objective_func(self, values):
     try:
         self._check_interrupt()
         pipeline = self.init_pipeline(values)
         loss, report_df = self._fit_predict_loss(pipeline)
         return loss, report_df
     except Exception as e:
         simple_logger.exception(e)
         simple_logger.error(values)
         return 1.0, self._add_loss_and_time_to_report(0, 0)
Пример #3
0
 def _decode_data(data, key):
     if data:
         try:
             data = gzip.decompress(data)
         except (OSError, TypeError):
             pass  # not gzip compressed
         try:
             data = json.loads(data)
         except Exception as e:
             logger.exception(e)
             logger.error(f'Failed unpacking redis query. key: {key}, response: {data}')
     return data
Пример #4
0
 def _model_reloading_loop(self):
     time.sleep(self._time_jitter())
     while self.keep_reloading:
         try:
             new_model_s3_path = self._latest_s3_model_path()
             if new_model_s3_path == self._current_model_path:
                 logger.info('Model path unchanged, not reloading. %s' %
                             new_model_s3_path)
             else:
                 updated_model = S3FileIO(
                     self._s3_bucket).unpickle(new_model_s3_path)
                 self._test_loaded_model(updated_model)
                 self.model = updated_model
                 self._current_model_path = new_model_s3_path
                 logger.info('Loaded updated model from S3. %s' %
                             new_model_s3_path)
         except Exception as e:
             logger.error('Failed model update. %s' % str(e))
             logger.exception(e)
             if self.model is None:
                 raise EnvironmentError('Could not load model on startup.')
         time.sleep(self._update_interval_seconds + self._time_jitter())
Пример #5
0
    def query(self, index_key, index_value):
        """
        example:
            table = RedisTable('p-bla-bla')
            result_dict = table.query('uuid', '1234')

        :returns response JSON as dict, None if not found, or response string if JSON conversion fails
        """
        key = self.table_index_key(index_key, index_value)
        data = self.get(key)
        if data:
            try:
                data = gzip.decompress(data)
            except (OSError, TypeError):
                pass  # not gzip compressed
            try:
                data = json.loads(data)
            except Exception as e:
                logger.exception(e)
                logger.error(
                    'Failed unpacking redis query. key: %s, response: %s' %
                    (key, data))
        return data