Error is a warning in parfeval function

조회 수: 3 (최근 30일)
Jim Hokanson
Jim Hokanson 2018년 1월 6일
답변: Jim Hokanson 2018년 1월 6일
I have the following (pseudo) code and I'm getting the following warning in my command window (2017b Windows).
function parallel_worker(q)
try
my_function(missing_variable)
catch ME
q.send(ME);
end
end
function my_function(v)
v = v + 1;
end
The receiving q is supposed to rethrow the error message.
Here's the caller:
function runExample()
q_receive = parallel.pool.DataQueue;
L1 = afterEach(q_receive, @handleQ);
%Launch the parallel daq session
%------------------------------------------------
fh = @parallel_worker;
feval_future = parfeval(gcp,fh,0,q_receive);
pause(5)
end
function handleQ(data)
rethrow(data)
end
%For testing:
%runExample should throw the warning below
%parallel_worker(1) - throws an error in the catch (as expected when input is a number not a queue)
I'm seeing: "Warning: Undefined function or variable 'missing_variable'" instead of: ME =
MException with properties:
identifier: 'MATLAB:UndefinedFunction'
message: 'Undefined function or variable 'missing_variable'.'
cause: {}
stack: [1×1 struct]
I know that in some cases I've seen errors throw which cause the future to stop. Why are some errors being converted into warnings?
Update: It appears that my problem may be with throwing ... one second ...

답변 (1개)

Jim Hokanson
Jim Hokanson 2018년 1월 6일
So, it appears the issue was not with the worker but in the client. After some debugging I tried this instead:
function handleQ(data)
disp('I ran!')
%rethrow(data)
end
In this case the code indicates it ran, and we also see that the warning was coming from rethrow(data), not from the worker.
This indicates that the afterEach callback operates more like a timer than a graphics callback, since the latter would actually throw the error.
So in summary, if you see warnings when you think you should be getting an error, it is because of throwing an error in the client callback method, not a warning that is being somehow thrown in the worker. This then begs the question of how to throw an error in the client when the worker fails ...

카테고리

Help CenterFile Exchange에서 Asynchronous Parallel Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by