Interrupt parfor from uiprogressdlg CancelRequested
5 views (last 30 days)
Show older comments
I have a parfor which processes a large number of files, and I use a cancelable uiprogressdlg with a parallel.pool.DataQueue to update the progress percentage as the files are processed. As expected, I cannot read the status of progress.CancelRequested inside the parfor, but can read it inside of my DataQueue afterEach called function (updateProgress).
I am not very particular on how the cancel operation is executed, so I tried throwing an error when CancelRequested was true, but DataQueue catches this, and converts it to a warning.
I would also be fine with replicating an interrupt like Ctrl-C, as that seems to be able to break out of a parfor without issue, but there does not seem to be a way to send this type of interrupt programmatically.
The only other solution I have found is to delete the parallel pool, which is rather crude (but it does work).
Is there a different way to throw an error that would not be caught? Or some way to accomplish this cancel operation without killing my parallel pool (so the program could be started again without waiting for the pool to be restarted)?
0 Comments
Accepted Answer
Raymond Norris
on 3 Feb 2021
I'm not entirely sure what you're hoping to have happen with the cancel, but I'll say that parfor can only be cancelled by Ctrl-C or killing the parallel pool. Perhaps a more graceful way is to use parfeval. This allows you the ability to update (i.e. DataQueue) and early termination (by cancelling the "futures").
Take a look at the "Cancel Array of Futures" example
In the second for loop, this could be updating your progress bar but also canceling your futures. It'd probably be best to post what you currently have to see if this addresses what you're asking for.
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!