|
73 | 73 | TupleNoPrint,
|
74 | 74 | check_function_inputs_match,
|
75 | 75 | component_or_layout_class,
|
76 |
| - get_cancel_function, |
| 76 | + get_cancelled_fn_indices, |
77 | 77 | get_continuous_fn,
|
78 | 78 | get_package_version,
|
79 | 79 | get_upload_folder,
|
@@ -541,12 +541,7 @@ def __init__(
|
541 | 541 | self.rendered_in = rendered_in
|
542 | 542 |
|
543 | 543 | # We need to keep track of which events are cancel events
|
544 |
| - # in two places: |
545 |
| - # 1. So that we can skip postprocessing for cancel events. |
546 |
| - # They return event_ids that have been cancelled but there |
547 |
| - # are no output components |
548 |
| - # 2. So that we can place the ProcessCompletedMessage in the |
549 |
| - # event stream so that clients can close the stream when necessary |
| 544 | + # so that the client can call the /cancel route directly |
550 | 545 | self.is_cancel_function = is_cancel_function
|
551 | 546 |
|
552 | 547 | self.spaces_auto_wrap()
|
@@ -589,6 +584,7 @@ def get_config(self):
|
589 | 584 | "types": {
|
590 | 585 | "continuous": self.types_continuous,
|
591 | 586 | "generator": self.types_generator,
|
| 587 | + "cancel": self.is_cancel_function, |
592 | 588 | },
|
593 | 589 | "collects_event_data": self.collects_event_data,
|
594 | 590 | "trigger_after": self.trigger_after,
|
@@ -1377,7 +1373,7 @@ def render(self):
|
1377 | 1373 | updated_cancels = [
|
1378 | 1374 | root_context.fns[i].get_config() for i in dependency.cancels
|
1379 | 1375 | ]
|
1380 |
| - dependency.fn = get_cancel_function(updated_cancels)[0] |
| 1376 | + dependency.cancels = get_cancelled_fn_indices(updated_cancels) |
1381 | 1377 | root_context.fns[root_context.fn_id] = dependency
|
1382 | 1378 | root_context.fn_id += 1
|
1383 | 1379 | Context.root_block.temp_file_sets.extend(self.temp_file_sets)
|
@@ -1694,17 +1690,9 @@ async def postprocess_data(
|
1694 | 1690 | block_fn: BlockFunction,
|
1695 | 1691 | predictions: list | dict,
|
1696 | 1692 | state: SessionState | None,
|
1697 |
| - ) -> Any: |
| 1693 | + ) -> list[Any]: |
1698 | 1694 | state = state or SessionState(self)
|
1699 | 1695 |
|
1700 |
| - # If the function is a cancel function, 'predictions' are the ids of |
1701 |
| - # the event in the queue that has been cancelled. We need these |
1702 |
| - # so that the server can put the ProcessCompleted message in the event stream |
1703 |
| - # Cancel events have no output components, so we need to return early otherise the output |
1704 |
| - # be None. |
1705 |
| - if block_fn.is_cancel_function: |
1706 |
| - return predictions |
1707 |
| - |
1708 | 1696 | if isinstance(predictions, dict) and len(predictions) > 0:
|
1709 | 1697 | predictions = convert_component_dict_to_list(
|
1710 | 1698 | [block._id for block in block_fn.outputs], predictions
|
@@ -1920,7 +1908,7 @@ async def process_api(
|
1920 | 1908 | for o in zip(*preds)
|
1921 | 1909 | ]
|
1922 | 1910 | if root_path is not None:
|
1923 |
| - data = processing_utils.add_root_url(data, root_path, None) |
| 1911 | + data = processing_utils.add_root_url(data, root_path, None) # type: ignore |
1924 | 1912 | data = list(zip(*data))
|
1925 | 1913 | is_generating, iterator = None, None
|
1926 | 1914 | else:
|
|
0 commit comments