Skip to content

Commit

Permalink
added some more flushes in the hopes of fixing the random failures on…
Browse files Browse the repository at this point in the history
… travis and appveyor
  • Loading branch information
Qwlouse committed Jan 5, 2017
1 parent fa0cb98 commit c99ded5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ def option_hook(self, function):
dictionary. That is, the dictionary of commandline options used for
this run.
NOTE: The decorated function MUST have an argument called options.
NOTE: While the options still contain the COMMAND and UPDATE entries,
changing them has no effect. Only flags (starting with '--') can
be modified.
.. note::
The decorated function MUST have an argument called options.
The options also contain ``'COMMAND'`` and ``'UPDATE'`` entries,
but changing them has no effect. Only modification on
flags (entries starting with ``'--'``) are considered.
"""
sig = Signature(function)
if "options" not in sig.arguments:
Expand Down
11 changes: 7 additions & 4 deletions sacred/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import tempfile

from sacred.randomness import set_global_seed
from sacred.utils import tee_output, ObserverError, SacredInterrupt, join_paths
from sacred.utils import (tee_output, ObserverError, SacredInterrupt,
join_paths, flush)


__sacred__ = True # marks files that should be filtered from stack traces
Expand Down Expand Up @@ -195,16 +196,18 @@ def __call__(self, *args):
raise
finally:
self._warn_about_failed_observers()
self.captured_out = self._get_captured_output()
self._get_captured_output()

return self.result

def _get_captured_output(self):
flush()
self._output_file.flush()
self._output_file.seek(0)
text = self._output_file.read().decode()
if self.captured_out_filter is not None:
text = self.captured_out_filter(text)
return text
self.captured_out = text

def _start_heartbeat(self):
self._emit_heartbeat()
Expand Down Expand Up @@ -272,7 +275,7 @@ def _emit_started(self):

def _emit_heartbeat(self):
beat_time = datetime.datetime.now()
self.captured_out = self._get_captured_output()
self._get_captured_output()
for observer in self.observers:
self._safe_call(observer, 'heartbeat_event',
info=self.info,
Expand Down
1 change: 1 addition & 0 deletions sacred/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def tee_output(target):
tee_stdout.wait()
tee_stderr.wait()
finally:
flush()
os.close(saved_stdout_fd)
os.close(saved_stderr_fd)

Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def test_convert_camel_case_to_snake_case(name, expected):
('abc\rdef', 'def'),
('abc\r', 'abc'),
('abc\rd', 'dbc'),
('abc\r\nd', 'abc\nd'),
('abc\ndef\rg', 'abc\ngef'),
('abc\ndef\r\rg', 'abc\ngef')
])
Expand Down

0 comments on commit c99ded5

Please sign in to comment.