Main Content


Cancel blocks in pipeline that are running in parallel

Since R2023a



cancel(pipeline) stops all blocks in the pipeline that are currently running in a parallel environment. The function also prevents new blocks from being queued. The function has no effect on the blocks that have been completed prior to calling the function.


collapse all

Import the pipeline and block objects needed for the example.

import bioinfo.pipeline.Pipeline
import bioinfo.pipeline.block.*

Create a pipeline.

P = Pipeline;

Add some pause blocks for illustration purposes. Each block pauses for 1 and 10 seconds, respectively.

PB1 = UserFunction(@() pause(1));
PB2 = UserFunction(@() pause(10));

Run the pipeline in parallel.

Starting parallel pool (parpool) using the 'Processes' profile ...
Connected to parallel pool with 4 workers.

Let the pipeline run for a few seconds in parallel. Then cancel the pipeline while it is still running.


Check the process table that contains the run status of each block. Set Expanded to true to expand the process table variable values which are in cell arrays.

t = processTable(P,Expanded=true)
t=2×5 table
         Block          Status          RunStart                 RunEnd              RunErrors    
    ________________    ______    ____________________    ____________________    ________________

    "UserFunction_1"    Error     26-Jul-2023 08:51:44    26-Jul-2023 08:51:44    {1×1 MException}
    "UserFunction_2"    Error     26-Jul-2023 08:51:44    26-Jul-2023 08:51:44    {1×1 MException}

You can extract more information from the process table. For example, check the run status of the first block.

PB1Info = t(1,:);
ans = 
  RunStatus enumeration


Check any error message associated with the block.

ans = 
  MException with properties:

    identifier: 'parallel:fevalqueue:ExecutionCancelled'
       message: 'Execution of the future was cancelled.'
         cause: {}
         stack: [0×1 struct]
    Correction: []

Input Arguments

collapse all

Bioinformatics pipeline, specified as a bioinfo.pipeline.Pipeline object.

Version History

Introduced in R2023a