Skip to content

Commit 7ea6e48

Browse files
committed
[MCP] fix tiny-agents on Windows (#3116)
* fix tiny-agents on Windows * fix windows * trigger * sanity check * fix * remove test * nit * nit * revert * trigger
1 parent a97424f commit 7ea6e48

File tree

1 file changed

+13
-5
lines changed
  • src/huggingface_hub/inference/_mcp

1 file changed

+13
-5
lines changed

src/huggingface_hub/inference/_mcp/cli.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ def _sigint_handler() -> None:
6363
os._exit(130)
6464

6565
try:
66-
loop.add_signal_handler(signal.SIGINT, _sigint_handler)
67-
66+
sigint_registered_in_loop = False
67+
try:
68+
loop.add_signal_handler(signal.SIGINT, _sigint_handler)
69+
sigint_registered_in_loop = True
70+
except (AttributeError, NotImplementedError):
71+
# Windows (or any loop that doesn't support it) : fall back to sync
72+
signal.signal(signal.SIGINT, lambda *_: _sigint_handler())
6873
async with Agent(
6974
provider=config["provider"],
7075
model=config["model"],
@@ -122,9 +127,12 @@ def _sigint_handler() -> None:
122127
first_sigint = True # Allow graceful interrupt for the next command
123128

124129
finally:
125-
if loop and not loop.is_closed():
126-
loop.remove_signal_handler(signal.SIGINT)
127-
elif original_sigint_handler:
130+
if sigint_registered_in_loop:
131+
try:
132+
loop.remove_signal_handler(signal.SIGINT)
133+
except (AttributeError, NotImplementedError):
134+
pass
135+
else:
128136
signal.signal(signal.SIGINT, original_sigint_handler)
129137

130138

0 commit comments

Comments
 (0)