File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
src/huggingface_hub/inference/_mcp Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments