Beispiel #1
0
    def __call__(self, *args):
        r"""Start this run.

        Parameters
        ----------
        \*args
            parameters passed to the main function

        Returns
        -------
            the return value of the main function
        """
        if self.start_time is not None:
            raise RuntimeError('A run can only be started once. '
                               '(Last start was {})'.format(self.start_time))

        if self.unobserved:
            self.observers = []

        self.warn_if_unobserved()
        set_global_seed(self.config['seed'])

        if self.queue_only:
            self._emit_queued()
            return
        try:
            try:
                with NamedTemporaryFile() as f, tee_output(f) as final_out:
                    self._output_file = f
                    self._emit_started()
                    self._start_heartbeat()
                    self._execute_pre_run_hooks()
                    self.result = self.main_function(*args)
                    self._execute_post_run_hooks()
                    if self.result is not None:
                        self.run_logger.info('Result: {}'.format(self.result))
                    elapsed_time = self._stop_time()
                    self.run_logger.info('Completed after %s', elapsed_time)
            finally:
                self.captured_out = final_out[0]
                if self.captured_out_filter is not None:
                    self.captured_out = self.captured_out_filter(
                        self.captured_out)
            self._stop_heartbeat()
            self._emit_completed(self.result)
        except (SacredInterrupt, KeyboardInterrupt) as e:
            self._stop_heartbeat()
            status = getattr(e, 'STATUS', 'INTERRUPTED')
            self._emit_interrupted(status)
            raise
        except:
            exc_type, exc_value, trace = sys.exc_info()
            self._stop_heartbeat()
            self._emit_failed(exc_type, exc_value, trace.tb_next)
            raise
        finally:
            self._warn_about_failed_observers()

        return self.result
Beispiel #2
0
    def __call__(self, *args):
        """Start this run.

        :param args: parameters passed to the main function
        :return: the return value of the main function
        """
        if self.start_time is not None:
            raise RuntimeError('A run can only be started once. '
                               '(Last start was {})'.format(self.start_time))

        if self.unobserved:
            self.observers = []

        self.warn_if_unobserved()
        set_global_seed(self.config['seed'])
        with tee_output() as self.captured_out:
            self.run_logger.info('Started')

            self._emit_started()
            self._start_heartbeat()
            try:
                self._execute_pre_run_hooks()
                self.result = self.main_function(*args)
                self._execute_post_run_hooks()
                self._stop_heartbeat()
                self._emit_completed(self.result)
                return self.result
            except KeyboardInterrupt:
                self._stop_heartbeat()
                self._emit_interrupted()
                raise
            except:
                exc_type, exc_value, trace = sys.exc_info()
                self._stop_heartbeat()
                self._emit_failed(exc_type, exc_value, trace.tb_next)
                raise
            finally:
                self._warn_about_failed_observers()
                self.captured_out.flush()
                self.captured_out = self.captured_out.getvalue()
                self.final = True
Beispiel #3
0
 def __call__(self, *args):
     set_global_seed(self.config['seed'])
     with tee_output() as self.captured_out:
         self.logger.info('Started')
         self._emit_started()
         self._start_heartbeat()
         try:
             self.result = self.main_function(*args)
             self._stop_heartbeat()
             self._emit_completed(self.result)
             return self.result
         except KeyboardInterrupt:
             self._stop_heartbeat()
             self._emit_interrupted()
             raise
         except:
             exc_type, exc_value, trace = sys.exc_info()
             self._stop_heartbeat()
             self._emit_failed(exc_type, exc_value, trace.tb_next)
             raise
         finally:
             self._warn_about_failed_observers()
Beispiel #4
0
 def __call__(self, *args):
     set_global_seed(self.config['seed'])
     with tee_output() as self.captured_out:
         self.logger.info('Started')
         self._emit_started()
         self._start_heartbeat()
         try:
             self.result = self.main_function(*args)
             self._stop_heartbeat()
             self._emit_completed(self.result)
             return self.result
         except KeyboardInterrupt:
             self._stop_heartbeat()
             self._emit_interrupted()
             raise
         except:
             exc_type, exc_value, trace = sys.exc_info()
             self._stop_heartbeat()
             self._emit_failed(exc_type, exc_value, trace.tb_next)
             raise
         finally:
             self._warn_about_failed_observers()
Beispiel #5
0
    def __call__(self, *args):
        r"""Start this run.

        Parameters
        ----------
        \*args
            parameters passed to the main function

        Returns
        -------
            the return value of the main function

        """
        if self.start_time is not None:
            raise RuntimeError('A run can only be started once. '
                               '(Last start was {})'.format(self.start_time))

        if self.unobserved:
            self.observers = []
        else:
            self.observers = sorted(self.observers, key=lambda x: -x.priority)

        self.warn_if_unobserved()
        set_global_seed(self.config['seed'])

        if self.capture_mode is None and not self.observers:
            capture_mode = "no"
        else:
            capture_mode = self.capture_mode
        capture_mode, capture_stdout = get_stdcapturer(capture_mode)
        self.run_logger.debug('Using capture mode "%s"', capture_mode)

        if self.queue_only:
            self._emit_queued()
            return
        try:
            with capture_stdout() as self._output_file:
                self._emit_started()
                self._start_heartbeat()
                self._execute_pre_run_hooks()
                self.result = self.main_function(*args)
                self._execute_post_run_hooks()
                if self.result is not None:
                    self.run_logger.info('Result: {}'.format(self.result))
                elapsed_time = self._stop_time()
                self.run_logger.info('Completed after %s', elapsed_time)
                self._get_captured_output()
            self._stop_heartbeat()
            self._emit_completed(self.result)
        except (SacredInterrupt, KeyboardInterrupt) as e:
            self._stop_heartbeat()
            status = getattr(e, 'STATUS', 'INTERRUPTED')
            self._emit_interrupted(status)
            raise
        except Exception:
            exc_type, exc_value, trace = sys.exc_info()
            self._stop_heartbeat()
            self._emit_failed(exc_type, exc_value, trace.tb_next)
            raise
        finally:
            self._warn_about_failed_observers()

        return self.result
Beispiel #6
0
    def __call__(self, *args):
        r"""Start this run.

        Parameters
        ----------
        \*args
            parameters passed to the main function

        Returns
        -------
            the return value of the main function

        """
        if self.start_time is not None:
            raise RuntimeError('A run can only be started once. '
                               '(Last start was {})'.format(self.start_time))

        if self.unobserved:
            self.observers = []
        else:
            self.observers = sorted(self.observers, key=lambda x: -x.priority)

        self.warn_if_unobserved()
        set_global_seed(self.config['seed'])

        if self.capture_mode is None and not self.observers:
            capture_mode = "no"
        else:
            capture_mode = self.capture_mode
        capture_mode, capture_stdout = get_stdcapturer(capture_mode)
        self.run_logger.debug('Using capture mode "%s"', capture_mode)

        if self.queue_only:
            self._emit_queued()
            return
        try:
            try:
                with capture_stdout() as out:
                    self._output_file = out
                    self._emit_started()
                    self._start_heartbeat()
                    self._execute_pre_run_hooks()
                    self.result = self.main_function(*args)
                    self._execute_post_run_hooks()
                    if self.result is not None:
                        self.run_logger.info('Result: {}'.format(self.result))
                    elapsed_time = self._stop_time()
                    self.run_logger.info('Completed after %s', elapsed_time)
                    self._get_captured_output()
            finally:
                self._get_captured_output()
            self._stop_heartbeat()
            self._emit_completed(self.result)
        except (SacredInterrupt, KeyboardInterrupt) as e:
            self._stop_heartbeat()
            status = getattr(e, 'STATUS', 'INTERRUPTED')
            self._emit_interrupted(status)
            raise
        except:
            exc_type, exc_value, trace = sys.exc_info()
            self._stop_heartbeat()
            self._emit_failed(exc_type, exc_value, trace.tb_next)
            raise
        finally:
            self._warn_about_failed_observers()

        return self.result