Skip to content

Commit

Permalink
fix(nyz): fix lock type bug
Browse files Browse the repository at this point in the history
  • Loading branch information
PaParaZz1 committed Jan 31, 2024
1 parent 09f8394 commit 6a20ae3
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ding/league/base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, cfg: EasyDict) -> None:
self.payoff = create_payoff(self.cfg.payoff)
metric_cfg = self.cfg.metric
self.metric_env = LeagueMetricEnv(metric_cfg.mu, metric_cfg.sigma, metric_cfg.tau, metric_cfg.draw_probability)
self._active_players_lock = LockContext(type_=LockContextType.THREAD_LOCK)
self._active_players_lock = LockContext(lock_type=LockContextType.THREAD_LOCK)
self._init_players()

def _init_players(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion ding/league/shared_payoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, cfg: EasyDict):
# ``_min_win_rate_games``` is used in ``self._win_rate`` method for calculating win rate between two players.
self._min_win_rate_games = cfg.get('min_win_rate_games', 8)
# Thread lock.
self._lock = LockContext(type_=LockContextType.THREAD_LOCK)
self._lock = LockContext(lock_type=LockContextType.THREAD_LOCK)

def __repr__(self) -> str:
headers = ["Home Player", "Away Player", "Wins", "Draws", "Losses", "Naive Win Rate"]
Expand Down
2 changes: 1 addition & 1 deletion ding/utils/data/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
if self.batch_size != self.chunk_size:
# job_result {batch_id: result_list} is used to store processed result in temporal.
self.job_result = self.manager.dict()
self.job_result_lock = LockContext(type_=LockContextType.PROCESS_LOCK)
self.job_result_lock = LockContext(lock_type=LockContextType.PROCESS_LOCK)
self.job_queue = self.mp_context.Queue(maxsize=queue_maxsize)
self.worker = [
self.mp_context.Process(
Expand Down
2 changes: 1 addition & 1 deletion ding/utils/data/structure/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, maxlen: int, timeout: float, monitor_interval: float = 1.0, _
# two separate receive and send queue for reducing interaction frequency and interference
self.receive_queue = Queue(maxlen)
self.send_queue = Queue(maxlen)
self.receive_lock = LockContext(type_=LockContextType.THREAD_LOCK)
self.receive_lock = LockContext(lock_type=LockContextType.THREAD_LOCK)
self._timeout_thread = Thread(target=self._timeout_monitor)
# the bool flag for gracefully shutting down the timeout monitor thread
self._timeout_thread_flag = True
Expand Down
2 changes: 1 addition & 1 deletion ding/worker/replay_buffer/advanced_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(
# Is used to generate a unique id for each data: If a new data is inserted, its unique id will be this.
self._next_unique_id = 0
# Lock to guarantee thread safe
self._lock = LockContext(type_=LockContextType.THREAD_LOCK)
self._lock = LockContext(lock_type=LockContextType.THREAD_LOCK)
# Point to the head of the circular queue. The true data is the stalest(oldest) data in this queue.
# Because buffer would remove data due to staleness or use count, and at the beginning when queue is not
# filled with data head would always be 0, so ``head`` may be not equal to ``tail``;
Expand Down
2 changes: 1 addition & 1 deletion ding/worker/replay_buffer/naive_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
# Point to the tail position where next data can be inserted, i.e. latest inserted data's next position.
self._tail = 0
# Lock to guarantee thread safe
self._lock = LockContext(type_=LockContextType.THREAD_LOCK)
self._lock = LockContext(lock_type=LockContextType.THREAD_LOCK)
self._end_flag = False
self._enable_track_used_data = self._cfg.enable_track_used_data
if self._enable_track_used_data:
Expand Down
4 changes: 2 additions & 2 deletions ding/worker/replay_buffer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def __init__(self, cfg) -> None:
window_seconds = cfg.window_seconds
self._decay_factor = 0.01 ** (1 / window_seconds)

self._push_lock = LockContext(type_=LockContextType.THREAD_LOCK)
self._sample_lock = LockContext(type_=LockContextType.THREAD_LOCK)
self._push_lock = LockContext(lock_type=LockContextType.THREAD_LOCK)
self._sample_lock = LockContext(lock_type=LockContextType.THREAD_LOCK)
self._history_push_count = 0
self._history_sample_count = 0

Expand Down

0 comments on commit 6a20ae3

Please sign in to comment.