Interrupt parfor from uiprogressdlg CancelRequested
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Raymond Norris
2021-2-3
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!