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 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Taylor
about 4 hours 前
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!