diff --git a/neps/runtime.py b/neps/runtime.py index 4ef2592a..ba84b051 100644 --- a/neps/runtime.py +++ b/neps/runtime.py @@ -358,7 +358,6 @@ def _get_next_trial(self) -> Trial | Literal["break"]: time.sleep(self._GRACE) # Give the lock some time with self.state._trial_lock.lock(): time.sleep(self._GRACE) # Give the lock some time - logger.info("I, MR WORKER %s obtained thel lock", self.worker_id) DEBUG_COUNT_FILE = Path(self.state.path / "DEBUG_COUNT_FILE") with DEBUG_COUNT_FILE.open("a") as f: f.write(f"locked: {time.time()}\n") @@ -395,7 +394,6 @@ def _get_next_trial(self) -> Trial | Literal["break"]: earliest_pending.id, ) return earliest_pending - logger.info("I, MR WORKER %s released thel lock", self.worker_id) with DEBUG_COUNT_FILE.open("a") as f: f.write(f"unlocked: {time.time()}\n") diff --git a/neps/state/filebased.py b/neps/state/filebased.py index 3142d2d8..794e9a1b 100644 --- a/neps/state/filebased.py +++ b/neps/state/filebased.py @@ -317,14 +317,13 @@ def lock( self, *, fail_if_locked: bool = False, + worker_id: str | None = None, ) -> Iterator[None]: self.lock_path.parent.mkdir(parents=True, exist_ok=True) - self.lock_path.touch(exist_ok=True) try: with pl.Lock( self.lock_path, - mode="wb", check_interval=self.poll, timeout=self.timeout, flags=FILELOCK_EXCLUSIVE_NONE_BLOCKING, @@ -332,7 +331,14 @@ def lock( ) as fh: import portalocker.portalocker as pl_module - logger.info(pl_module.LOCKER) + if worker_id is not None: + logger.debug( + "Worker %s acquired lock on %s using %s at %s", + worker_id, + self.lock_path, + pl_module.LOCKER, + time.time(), + ) fh.write(f"{time.time()}".encode("utf-8")) # noqa: UP012 os.fsync(fh) yield