Skip to content

Commit

Permalink
improved error-message when using @ex.automain in interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwlouse committed Apr 1, 2016
1 parent 04b6dfd commit 46b8f96
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ def my_main():
"""
captured = self.main(function)
if function.__module__ == '__main__':
# Ensure that automain is not used in interactive mode.
import inspect
main_filename = inspect.getfile(function)
if (main_filename == '<stdin>' or
(main_filename.startswith('<ipython-input-') and
main_filename.endswith('>'))):
raise RuntimeError('Cannot use @ex.automain decorator in '
'interactive mode. Use @ex.main instead.')

self.run_commandline()
return captured

Expand Down

0 comments on commit 46b8f96

Please sign in to comment.