From 57f5a1e4c0252436ecf2572da6973d054807add5 Mon Sep 17 00:00:00 2001 From: tangypnuaa Date: Mon, 1 Mar 2021 10:39:11 +0800 Subject: [PATCH] fix the issue that `time.clock()` method no longer exists in higher version of python, and close #30 --- alipy/experiment/stopping_criteria.py | 6 +++--- alipy/utils/multi_thread.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/alipy/experiment/stopping_criteria.py b/alipy/experiment/stopping_criteria.py index 5042450..c691489 100644 --- a/alipy/experiment/stopping_criteria.py +++ b/alipy/experiment/stopping_criteria.py @@ -66,7 +66,7 @@ def __init__(self, stopping_criteria=None, value=None): if not isinstance(value, float) and value is not None: value = float(value) if stopping_criteria == 'time_limit': - self._start_time = time.clock() + self._start_time = time.perf_counter() self.value = value # collect information @@ -102,7 +102,7 @@ def is_stop(self): else: return False elif self._stopping_criteria == 'time_limit': - if time.clock() - self._start_time >= self.value: + if time.perf_counter() - self._start_time >= self.value: return True else: return False @@ -132,7 +132,7 @@ def reset(self): Reset the current state to the initial. """ self.value = self._init_value - self._start_time = time.clock() + self._start_time = time.perf_counter() self._current_iter = 0 self._accum_cost = 0 self._current_unlabel = 100 diff --git a/alipy/utils/multi_thread.py b/alipy/utils/multi_thread.py index c623d88..fd52558 100644 --- a/alipy/utils/multi_thread.py +++ b/alipy/utils/multi_thread.py @@ -109,7 +109,7 @@ def __init__(self, examples, labels, train_idx, test_idx, label_index, unlabel_i assert max_thread > 0 self.__max_thread = max_thread # for controlling the print frequency - self._start_time = time.clock() + self._start_time = time.perf_counter() # for displaying the time elapse self._thread_time_elapse = [-1] * self._round_num # for recovering the workspace @@ -246,8 +246,8 @@ def __repr__(self): return str(tb) def _if_refresh(self): - if time.clock() - self._start_time > self._refresh_interval: - self._start_time = time.clock() + if time.perf_counter() - self._start_time > self._refresh_interval: + self._start_time = time.perf_counter() return True else: return False