Skip to content

Commit 6c9d470

Browse files
Fix: Make fcntl usage conditional in mcpm share for Windows compatibility (#166)
The `fcntl` module is not available on Windows, and its direct import was causing `ImportError` when `mcpm share` was invoked or its module (src/mcpm/commands/share.py) was loaded on Windows systems. This commit makes the import and usage of `fcntl` within the `make_non_blocking` function conditional on `os.name == 'posix'`. On non-POSIX systems (like Windows), the function will now do nothing. The existing code for reading from subprocess pipes in `mcpm share` utilizes `select.select()` with timeouts and handles `IOError`/`OSError` exceptions. This setup is expected to provide sufficient non-blocking behavior for reading subprocess output on Windows, even without an explicit `fcntl` call to set `O_NONBLOCK`. Note: Full dynamic testing of `mcpm share` on a Windows-like environment was not possible due to a Python version mismatch (environment: 3.10.17, project requires: >=3.11) in the available testing sandbox. This change addresses the direct `ImportError`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 30ebdb0 commit 6c9d470

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/mcpm/commands/share.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ def find_mcp_proxy() -> Optional[str]:
2929

3030
def make_non_blocking(file_obj):
3131
"""Make a file object non-blocking."""
32-
import fcntl
33-
34-
fd = file_obj.fileno()
35-
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
36-
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
32+
if os.name == 'posix':
33+
import fcntl
34+
35+
fd = file_obj.fileno()
36+
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
37+
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
38+
# On other platforms (e.g., Windows), we rely on the behavior of select()
39+
# and the non-blocking nature of readline() on Popen streams,
40+
# or the existing try-except for IOError/OSError.
3741

3842

3943
def wait_for_random_port(process: subprocess.Popen, timeout: int = 20) -> Optional[int]:

0 commit comments

Comments
 (0)