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:
63
63
os ._exit (130 )
64
64
65
65
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 ())
68
73
async with Agent (
69
74
provider = config ["provider" ],
70
75
model = config ["model" ],
@@ -122,9 +127,12 @@ def _sigint_handler() -> None:
122
127
first_sigint = True # Allow graceful interrupt for the next command
123
128
124
129
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 :
128
136
signal .signal (signal .SIGINT , original_sigint_handler )
129
137
130
138
You can’t perform that action at this time.
0 commit comments