class_docstr: This class initialises an application by building a TF graph,
  and maintaining a session. It controls the
  starting/stopping of an application. Applications should be
  implemented by inheriting ``niftynet.application.base_application``
  to be compatible with this driver.
class_docstr_tok: ["This","class","initialises","an","application","by","building","a","TF","graph",",","and","maintaining","a","session",".","It","controls","the","starting\/stopping","of","an","application",".","Applications","should","be","implemented","by","inheriting","``","niftynet.application.base_application","``","to","be","compatible","with","this","driver","."]
docstr: Running ``loop_step`` with ``IterationMessage`` instances
  generated by ``iteration_generator``.
  
  This loop stops when any of the condition satisfied:
      1. no more element from the ``iteration_generator``;
      2. ``application.interpret_output`` returns False;
      3. any exception raised.
  
  Broadcasting SESS_* signals at the beginning and end of this method.
  
  This function should be used in a context of
  ``tf.Session`` or ``session.as_default()``.
  
  :param application: a niftynet.application instance, application
      will provides ``tensors`` to be fetched by ``tf.session.run()``.
  :param iteration_messages:
      a generator of ``engine.IterationMessage`` instances
  :param loop_status: optional dictionary used to capture the loop status,
      useful when the loop exited in an unexpected manner.
  :return:
docstr_tok: ["Running","``","loop_step","``","with","``","IterationMessage","``","instances","generated","by","``","iteration_generator","``",".","This","loop","stops","when","any","of","the","condition","satisfied",":","1.","no","more","element","from","the","``","iteration_generator","``",";","2",".","``","application.interpret_output","``","returns","False",";","3.","any","exception","raised",".","Broadcasting","SESS_","*","signals","at","the","beginning","and","end","of","this","method",".","This","function","should","be","used","in","a","context","of","``","tf.Session","``","or","``","session.as_default","(",")","``",".",":","param","application",":","a","niftynet.application","instance",",","application","will","provides","``","tensors","``","to","be","fetched","by","``","tf.session.run","(",")","``",".",":","param","iteration_messages",":","a","generator","of","``","engine.IterationMessage","``","instances",":","param","loop_status",":","optional","dictionary","used","to","capture","the","loop","status",",","useful","when","the","loop","exited","in","an","unexpected","manner",".",":","return",":"]
code: def loop(application, iteration_messages=(), loop_status=None):
      """
      Running ``loop_step`` with ``IterationMessage`` instances
      generated by ``iteration_generator``.
  
      This loop stops when any of the condition satisfied:
          1. no more element from the ``iteration_generator``;
          2. ``application.interpret_output`` returns False;
          3. any exception raised.
  
      Broadcasting SESS_* signals at the beginning and end of this method.
  
      This function should be used in a context of
      ``tf.Session`` or ``session.as_default()``.
  
      :param application: a niftynet.application instance, application
          will provides ``tensors`` to be fetched by ``tf.session.run()``.
      :param iteration_messages:
          a generator of ``engine.IterationMessage`` instances
      :param loop_status: optional dictionary used to capture the loop status,
          useful when the loop exited in an unexpected manner.
      :return:
      """
      loop_status = loop_status or {}
      for iter_msg in iteration_messages:
          loop_status["current_iter"] = iter_msg.current_iter
  
          # run an iteration
          ApplicationDriver.loop_step(application, iter_msg)
  
          # Checking stopping conditions
          if iter_msg.should_stop:
              tf.logging.info(
                  "stopping -- event handler: %s.", iter_msg.should_stop
              )
              break
      # loop finished without any exception
      loop_status["normal_exit"] = True
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import time
  import tensorflow
  from niftynet.engine.application_factory import ApplicationFactory, EventHandlerFactory, IteratorFactory
  from niftynet.engine.application_iteration import IterationMessage
  from niftynet.engine.application_variables import GradientsCollector, OutputsCollector
  from niftynet.engine.signal import TRAIN, ITER_STARTED, ITER_FINISHED, GRAPH_CREATED, SESS_FINISHED, SESS_STARTED
  from niftynet.io.image_sets_partitioner import ImageSetsPartitioner
  from niftynet.io.misc_io import infer_latest_model_file
  from niftynet.utilities.user_parameters_default import DEFAULT_EVENT_HANDLERS, DEFAULT_ITERATION_GENERATOR
  from niftynet.utilities.util_common import set_cuda_device, tf_config, device_string
  from niftynet.utilities.util_common import traverse_nested
label_desc: Use image node_id 6 for calling the ApplicationDriver obj's underlying member method code with example usage: obj.loop(application, iteration_messages, loop_status) without return types