Skip to content

Commit

Permalink
debug: MOREEEEEEEE
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiebergman committed Dec 9, 2024
1 parent f3d23d1 commit c440b7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 0 additions & 2 deletions neps/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")

Expand Down
12 changes: 9 additions & 3 deletions neps/state/filebased.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,28 @@ 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,
fail_when_locked=fail_if_locked,
) 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
Expand Down

0 comments on commit c440b7e

Please sign in to comment.