Skip to content

Commit

Permalink
better treatment of SpawnedMatlab.disconnect cases
Browse files Browse the repository at this point in the history
  • Loading branch information
EastEriq committed Dec 23, 2021
1 parent 90830c8 commit 4f09b46
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions +obs/+util/@SpawnedMatlab/disconnect.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
function disconnect(S)
% try to quit gracefully the spawned session (if it responds normally)

if isa(S.Messenger,'obs.util.Messenger')

% we check S.Status, because the logic is already in there.
% If it is 'disconnected', we do not waste time in
% checking communinication and getting a timeout without need.
alive=strcmp(S.Status,'alive');
if alive
% checking communication and getting a timeout without need.
status=S.Status;
if strcmp(status,'alive')
S.Messenger.send('exit')
end
% if the slave is dead/unresponsive, or send times out, kill
if ~alive || ~isempty(S.Messenger.LastError)

% if the slave is dead/unresponsive, or send() times out, kill it
if isempty(S.Messenger.LastError)
S.PID=[];
S.Status='disconnected';
else
S.report(['graceful exit of slave session ' S.Id ...
' timed out, attempting to kill\n'])
' timed out'])
end

if ~isempty(S.PID)
S.report('attempting to kill slave session %s\n',S.Id)
S.kill
end
end
Expand Down

0 comments on commit 4f09b46

Please sign in to comment.