当前位置: 首页>>代码示例>>Python>>正文


Python errors.CancelledError方法代码示例

本文整理汇总了Python中tensorflow.python.framework.errors.CancelledError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.CancelledError方法的具体用法?Python errors.CancelledError怎么用?Python errors.CancelledError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.framework.errors的用法示例。


在下文中一共展示了errors.CancelledError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import CancelledError [as 别名]
def __init__(self, queue=None, enqueue_ops=None, close_op=None,
               cancel_op=None, feed_fns=None,
               queue_closed_exception_types=None):
    """Initialize the queue runner.

    For further documentation, see `queue_runner.py`. Note that
    `FeedingQueueRunner` does not support construction from protobuffer nor
    serialization to protobuffer.

    Args:
      queue: A `Queue`.
      enqueue_ops: List of enqueue ops to run in threads later.
      close_op: Op to close the queue. Pending enqueue ops are preserved.
      cancel_op: Op to close the queue and cancel pending enqueue ops.
      feed_fns: a list of functions that return a dictionary mapping fed
        `Tensor`s to values. Must be the same length as `enqueue_ops`.
      queue_closed_exception_types: Optional tuple of Exception types that
        indicate that the queue has been closed when raised during an enqueue
        operation.  Defaults to
        `(tf.errors.OutOfRangeError, tf.errors.CancelledError)`.

    Raises:
      ValueError: `feed_fns` is not `None` and has different length than
        `enqueue_ops`.
    """
    if queue_closed_exception_types is None:
      queue_closed_exception_types = (
          errors.OutOfRangeError, errors.CancelledError)
    super(_FeedingQueueRunner, self).__init__(
        queue, enqueue_ops, close_op,
        cancel_op, queue_closed_exception_types=queue_closed_exception_types)
    if feed_fns is None:
      self._feed_fns = [None for _ in enqueue_ops]
    else:
      if len(feed_fns) != len(enqueue_ops):
        raise ValueError(
            "If feed_fns is not None, it must have the same length as "
            "enqueue_ops.")
      self._feed_fns = feed_fns

  # pylint: disable=broad-except 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:43,代码来源:feeding_queue_runner.py

示例2: __init__

# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import CancelledError [as 别名]
def __init__(self, queue=None, enqueue_ops=None, close_op=None,
               cancel_op=None, feed_fns=None,
               queue_closed_exception_types=None):
    """Initialize the queue runner.

    For further documentation, see `queue_runner.py`. Note that
    `FeedingQueueRunner` does not support construction from protobuffer nor
    serialization to protobuffer.

    Args:
      queue: A `Queue`.
      enqueue_ops: List of enqueue ops to run in threads later.
      close_op: Op to close the queue. Pending enqueue ops are preserved.
      cancel_op: Op to close the queue and cancel pending enqueue ops.
      feed_fns: a list of functions that return a dictionary mapping fed
        `Tensor`s to values. Must be the same length as `enqueue_ops`.
      queue_closed_exception_types: Optional tuple of Exception types that
        indicate that the queue has been closed when raised during an enqueue
        operation.  Defaults to
        `(tf.errors.OutOfRangeError, tf.errors.CancelledError)`.

    Raises:
      ValueError: `feed_fns` is not `None` and has different length than
        `enqueue_ops`.
    """
    if queue_closed_exception_types is None:
      queue_closed_exception_types = (
          errors.OutOfRangeError, errors.CancelledError)
    super(FeedingQueueRunner, self).__init__(
        queue, enqueue_ops, close_op,
        cancel_op, queue_closed_exception_types=queue_closed_exception_types)
    if feed_fns is None:
      self._feed_fns = [None for _ in enqueue_ops]
    else:
      if len(feed_fns) != len(enqueue_ops):
        raise ValueError(
            "If feed_fns is not None, it must have the same length as "
            "enqueue_ops.")
      self._feed_fns = feed_fns

  # pylint: disable=broad-except 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:43,代码来源:feeding_queue_runner.py

示例3: _run

# 需要导入模块: from tensorflow.python.framework import errors [as 别名]
# 或者: from tensorflow.python.framework.errors import CancelledError [as 别名]
def _run(self, sess, enqueue_op, feed_fn, coord=None):
    """Execute the enqueue op in a loop, close the queue in case of error.

    Args:
      sess: A `Session`.
      enqueue_op: The `Operation` to run.
      feed_fn: the feed function to pass to `sess.run`.
      coord: Optional `Coordinator` object for reporting errors and checking
        for stop conditions.

    """
    # TODO(jamieas): Reduce code duplication with `QueueRunner`.
    if coord:
      coord.register_thread(threading.current_thread())
    decremented = False
    try:
      while True:
        if coord and coord.should_stop():
          break
        try:
          feed_dict = None if feed_fn is None else feed_fn()
          sess.run(enqueue_op, feed_dict=feed_dict)
        except (errors.OutOfRangeError, errors.CancelledError):
          # This exception indicates that a queue was closed.
          with self._lock:
            self._runs_per_session[sess] -= 1
            decremented = True
            if self._runs_per_session[sess] == 0:
              try:
                sess.run(self._close_op)
              except Exception as e:
                # Intentionally ignore errors from close_op.
                logging.vlog(1, "Ignored exception: %s", str(e))
            return
    except Exception as e:
      # This catches all other exceptions.
      if coord:
        coord.request_stop(e)
      else:
        logging.error("Exception in QueueRunner: %s", str(e))
        with self._lock:
          self._exceptions_raised.append(e)
        raise
    finally:
      # Make sure we account for all terminations: normal or errors.
      if not decremented:
        with self._lock:
          self._runs_per_session[sess] -= 1 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:50,代码来源:feeding_queue_runner.py


注:本文中的tensorflow.python.framework.errors.CancelledError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。