Open the best-params lock with O_NONBLOCK so a pre-existing FIFO at
.optuna-best-params.lock no longer blocks the O_RDONLY shared-load open
until a writer appears (O_NOFOLLOW rejects symlinks but not FIFOs),
hanging strategy startup before the S_ISREG guard can reject the
non-regular file. The flag is inert on regular files and does not affect
the subsequent blocking flock() (governed by LOCK_NB, not the fd flag).
Addresses the unresolved P2 review thread on merged PR #185.
) -> Iterator[None]:
"""Serialize best-params I/O using a stable lock file."""
lock_path = best_params_path.parent / ".optuna-best-params.lock"
+ # O_NONBLOCK so a pre-existing FIFO (unlike a symlink, not caught by
+ # O_NOFOLLOW) cannot hang this open before the S_ISREG guard rejects it.
lock_fd = os.open(
lock_path,
(os.O_RDWR if exclusive else os.O_RDONLY)
| os.O_CREAT
| os.O_CLOEXEC
- | os.O_NOFOLLOW,
+ | os.O_NOFOLLOW
+ | os.O_NONBLOCK,
0o666,
)
try: