Skip to content

Commit

Permalink
print() warns when called before any samples are generated
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-lau committed Feb 23, 2014
1 parent ecc6d83 commit c633390
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions StanFit.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function process_exit(self,src,~)
if src.exitValue == 0
self.process_exit_success(src);
elseif src.exitValue == 143
% TODO: check that SIGTERM (143) is the same on windows/linux?
self.process_exit_success(src);
else
self.process_exit_failure(src);
Expand Down Expand Up @@ -194,14 +195,14 @@ function process_exit_failure(self,src)
function str = print(self,varargin)
% TODO:
% o this should allow multiple files and regexp.
% o this does not work when method=optim, should shortcut
% x this does not work when method=optim, should shortcut
%
% note that passing regexp through in the command does not work,
% need to implment search in matlab
% TODO: allow print parameters
% FIXME: ugh, if multiple fits were done with same output names
% print will just give the results from the last one. should
% StanModel generate unique names>>>
% StanModel generate unique names?
if strcmp(self.model.method,'optimize')
fprintf('%s\n',self.processes.stdout{:});
return;
Expand Down Expand Up @@ -233,12 +234,20 @@ function process_exit_failure(self,src)
p = processManager('command',command,...
'workingDir',self.model.working_dir,...
'wrap',100,...
'printStdout',false,...
'printStderr',false,...
'keepStdout',true,...
'keepStderr',true);
p.block(0.05);
if p.exitValue == 0
str = p.stdout;
fprintf('%s\n',str{:});
else
if any(strcmp(p.stdout,'Warning: non-fatal error reading adapation data'))...
|| any(strcmp(p.stdout,'Warning: non-fatal error reading samples'))
fprintf('Looks like print got called before any samples were saved.\n');
fprintf('Wait a bit longer, or attach a listener.\n');
end
str = p.stderr;
end
end
Expand All @@ -250,14 +259,8 @@ function block(self)
% FIXME: is_running can return false before self.loaded
if ~isempty(self.processes)%is_running(self) % stan called
% FIXME, what if callback fails??
count = 1;
while nansum(self.loaded) ~= numel(self.loaded)
java.lang.Thread.sleep(0.05*1000);
count = count + 1;
if count > 1000
warning('block() is taking too long');
break;
end
end
end
end
Expand Down

0 comments on commit c633390

Please sign in to comment.