Main Content

cancel

Cancel blocks in pipeline that are running in parallel

Since R2023a

Description

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.

example

Examples

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));
addBlock(P,[PB1,PB2]);

Run the pipeline in parallel.

run(P,UseParallel=true);
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.

cancel(P);

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,:);
PB1Info.Status
ans = 
  RunStatus enumeration

    Error

Check any error message associated with the block.

PB1Info.RunErrors{:}
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