def main_loop(self):
        # some final operations that might modify the graph
        logger.info("Preparing for training...")
        self._init_summary()
        get_global_step_var()   # ensure there is such var, before finalizing the graph
        callbacks = self.config.callbacks
        callbacks.before_train(self)
        self.config.session_init.init(self.sess)
        tf.get_default_graph().finalize()
        self._start_all_threads()

        with self.sess.as_default():
            try:
                self.global_step = get_global_step()
                logger.info("Start training with global_step={}".format(self.global_step))

                for epoch in range(self.config.starting_epoch, self.config.max_epoch+1):
                    with timed_operation(
                        'Epoch {}, global_step={}'.format(
                            epoch, self.global_step + self.config.step_per_epoch)):
                        for step in tqdm.trange(
                                self.config.step_per_epoch,
                                leave=True, mininterval=0.5,
                                dynamic_ncols=True, ascii=True):
                            if self.coord.should_stop():
                                return
                            self.run_step()
                            #callbacks.trigger_step()   # not useful?
                            self.global_step += 1
                        self.trigger_epoch()
            except (__HOLE__, Exception):
                raise
            finally:
                self.coord.request_stop()
                # Do I need to run queue.close?
                callbacks.after_train()
                self.summary_writer.close()
                self.sess.close()
dataset/ETHPy150Open ppwwyyxx/tensorpack/tensorpack/train/base.py/Trainer.main_loop