File tree Expand file tree Collapse file tree 2 files changed +25
-19
lines changed Expand file tree Collapse file tree 2 files changed +25
-19
lines changed Original file line number Diff line number Diff line change 12
12
from .exceptions import (
13
13
PreventUpdate ,
14
14
WildcardInLongCallback ,
15
- DuplicateCallback ,
16
15
MissingLongCallbackManagerError ,
17
16
LongCallbackError ,
18
17
)
@@ -171,25 +170,8 @@ def callback(
171
170
cancel_inputs = coerce_to_list (cancel )
172
171
validate_long_inputs (cancel_inputs )
173
172
174
- cancels_output = [Output (c .component_id , "id" ) for c in cancel_inputs ]
175
-
176
- try :
177
-
178
- @callback (cancels_output , cancel_inputs , prevent_initial_call = True )
179
- def cancel_call (* _ ):
180
- job_ids = flask .request .args .getlist ("cancelJob" )
181
- executor = (
182
- manager or context_value .get ().background_callback_manager
183
- )
184
- if job_ids :
185
- for job_id in job_ids :
186
- executor .terminate_job (job_id )
187
- return NoUpdate ()
188
-
189
- except DuplicateCallback :
190
- pass # Already a callback to cancel, will get the proper jobs from the store.
191
-
192
173
long_spec ["cancel" ] = [c .to_dict () for c in cancel_inputs ]
174
+ long_spec ["cancel_inputs" ] = cancel_inputs
193
175
194
176
if cache_args_to_ignore :
195
177
long_spec ["cache_args_to_ignore" ] = cache_args_to_ignore
Original file line number Diff line number Diff line change @@ -1316,6 +1316,30 @@ def _setup_server(self):
1316
1316
1317
1317
_validate .validate_long_callbacks (self .callback_map )
1318
1318
1319
+ cancels = set ()
1320
+
1321
+ for callback in self .callback_map .values ():
1322
+ cancel = callback .get ("long" , {}).pop ("cancel_inputs" )
1323
+ if cancel :
1324
+ cancels .update (cancel )
1325
+
1326
+ if cancels :
1327
+ for cancel_input in cancels :
1328
+
1329
+ # pylint: disable=cell-var-from-loop
1330
+ @self .callback (
1331
+ Output (cancel_input .component_id , "id" ),
1332
+ cancel_input ,
1333
+ prevent_initial_call = True ,
1334
+ )
1335
+ def cancel_call (* _ ):
1336
+ job_ids = flask .request .args .getlist ("cancelJob" )
1337
+ executor = _callback .context_value .get ().background_callback_manager
1338
+ if job_ids :
1339
+ for job_id in job_ids :
1340
+ executor .terminate_job (job_id )
1341
+ return no_update
1342
+
1319
1343
def _add_assets_resource (self , url_path , file_path ):
1320
1344
res = {"asset_path" : url_path , "filepath" : file_path }
1321
1345
if self .config .assets_external_path :
You can’t perform that action at this time.
0 commit comments