Skip to content

Conversation

@Eng-Ahmd
Copy link

@Eng-Ahmd Eng-Ahmd commented Nov 2, 2025

fix: Add Windows support to python_repl tool (#15)

Make python_repl tool cross-platform compatible to work on Windows, Linux, and macOS.

Problem

The original implementation relied on POSIX-specific features that are not available on Windows:

  • PTY operations (pty.openpty(), os.fork())
  • POSIX signals (SIGTERM, SIGKILL)
  • File descriptor operations (fcntl, termios, select)

This made the tool completely non-functional for Windows users.

Solution

Implemented a cross-platform execution strategy:

Core Changes:

  1. Platform Detection

    • Added IS_WINDOWS and IS_POSIX flags using platform.system()
    • Conditional imports for POSIX-only modules to prevent import errors on Windows
  2. New SubprocessExecutor Class

    • Cross-platform alternative using subprocess.Popen with pipes
    • Maintains state persistence through temporary script files
    • Handles output streaming with proper text encoding for Windows
    • Thread-safe output capture and cleanup
  3. Preserved PtyManager for Unix

    • Wrapped existing PtyManager in if IS_POSIX: conditional
    • No changes to Unix/Linux/macOS functionality
    • Maintains superior interactive PTY experience on POSIX systems
  4. Execution Logic

    • Windows: Uses SubprocessExecutor for all modes
    • Unix interactive: Uses PtyManager (original behavior)
    • Unix non-interactive: Uses direct execution (original behavior)
    • Graceful fallback ensures code always executes

Technical Details:

  • State persistence works identically across all platforms using dill
  • Output capture and ANSI cleaning preserved
  • Error handling and logging maintained
  • User confirmation flow unchanged
  • All safety features retained

Backward Compatibility:

  • Zero breaking changes for Unix/Linux/macOS users
  • PTY mode still used by default on POSIX systems
  • All existing features and behaviors preserved

Testing:

Verified on:

  • Windows 11

Closes #15

The python_repl tool was POSIX-only due to PTY dependencies (pty, fcntl, termios). Added cross-platform SubprocessExecutor class for Windows while preserving existing PtyManager for Unix systems. No breaking changes.

Changes:

- Added platform detection (IS_WINDOWS, IS_POSIX)

- Created SubprocessExecutor using subprocess.Popen for Windows

- Conditional PtyManager import for POSIX systems only

- Smart execution routing based on platform

- Enhanced docs with cross-platform support info

Closes strands-agents#15
@Eng-Ahmd Eng-Ahmd requested a review from a team as a code owner November 2, 2025 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ModuleNotFoundError: No module named 'fcntl' when running on Windows machine

1 participant