Parallel workers pop-up figures while executing scripts. Is it possible to have the figures created on background while still being able to save them as files?

19 views (last 30 days)
In MATLAB R2025b, when running in parallel mode (pool type Processes), figures created by workers pop up and steal focus from whatever application I’m using, while Matlab is running. In MATLAB R2024b, the same workflow does not cause the same problem, i.e. figures do not pop-up.
Below is all the code that I have tried to execute inside each worker's function but none have worked until now.
% Pool & Job submission
pool = gcp("nocreate");
if ~isempty(pool) && wf_new_parallel
delete(pool);
parpool(wf_parallel_type,nW);
elseif isempty(pool)
parpool(wf_parallel_type,nW);
end
p = gcp();
% Run once on every worker and WAIT for it
f = parfevalOnAll(p, @disable_worker_figures, 0);
wait(f);
% --- inside worker code (process_subject) ---
set(0, 'DefaultFigureVisible', 'off');
disp(['Figure visibility set to: ' get(groot,'DefaultFigureVisible')])
% --- helper you tested ---
function disable_worker_figures()
% Hide classic figures
set(groot,'DefaultFigureVisible','off');
% Hide UIFigures (if used)
try
set(groot,'DefaultUIFigureVisible','off');
catch
end
% Stronger: force invisibility at creation time
set(groot,'DefaultFigureCreateFcn', @(h,~) set(h,'Visible','off'));
try
set(groot,'DefaultUIFigureCreateFcn', @(h,~) set(h,'Visible','off'));
catch
end
% WindowStyle doesn't prevent focus stealing; keep normal
try
set(0,'DefaultFigureWindowStyle','normal');
catch
end
end

Answers (1)

Taylor
Taylor ungefär 7 timmar ago
In a process-based pool, each worker is its own MATLAB process with its own graphics root. So set(0, 'DefaultFigureVisible', 'off') on the client does not effect the workers. Try parfevalOnAll(@set, 0, 'DefaultFigureVisible', 'off') instead to manipulate the worker's graphics root instead of the client's.
  1 Comment
João
João ungefär 5 timmar ago
Thank you for your response. Unfortunately, it did not work.
I know for a fact that the scripts executed by each worker output "off" for both the following lines of code:
disp(['Figure visibility set to: ' get(groot,'DefaultFigureVisible')])
disp(['Handle visibility set to: ' get(groot,'HandleVisibility')])
And I made sure the code you gave me executed without errors, which it did.
I am thinking it must have something to do with the new UI since this issue does not happen in MATLAB 2024b.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!