Skip to content

Commit a9777bf

Browse files
fix: improve fcntl import robustness and fix unreachable code
- Replace platform-based fcntl import with try/except for better cross-platform compatibility - Fix unreachable warning code branch that could never execute - Remove misleading msvcrt reference in Unix-only warning message - Now gracefully handles environments where fcntl is unavailable (GAE, Pyodide, etc.) - All reviewer feedback from Qodo, CodeRabbit, Gemini, Copilot, and Greptile addressed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent 09f7f4e commit a9777bf

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • src/praisonai-agents/praisonaiagents/session

src/praisonai-agents/praisonaiagents/session/store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import time
1616

1717
# fcntl is Unix-only; on Windows, use msvcrt for file locking
18-
if sys.platform != 'win32':
18+
try:
1919
import fcntl
2020
_HAS_FCNTL = True
21-
else:
21+
except ImportError:
2222
_HAS_FCNTL = False
2323
from dataclasses import dataclass, field
2424
from datetime import datetime, timezone
@@ -162,11 +162,11 @@ def acquire(self) -> bool:
162162
if _HAS_FCNTL:
163163
fcntl.flock(self._lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
164164
else:
165-
# Warn once about degraded locking (should never happen with current platform detection)
165+
# Warn once about degraded locking
166166
global _WARNED_NO_FCNTL
167167
if not _WARNED_NO_FCNTL:
168168
logger.warning(
169-
"File locking unavailable on this platform (no fcntl/msvcrt); "
169+
"File locking unavailable on this platform (no fcntl); "
170170
"concurrent writers may corrupt session files."
171171
)
172172
_WARNED_NO_FCNTL = True

0 commit comments

Comments
 (0)