Python google.appengine.runtime.apiproxy_errors.CancelledError() Examples

The following are code examples for showing how to use google.appengine.runtime.apiproxy_errors.CancelledError(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: luci-py   Author: luci   File: utils.py    Apache License 2.0 5 votes vote down vote up
def _get_memory_usage():
  """Returns the amount of memory available as an float in MiB."""
  try:
    return apiruntime.runtime.memory_usage().current()
  except (AssertionError,
          apiproxy_errors.CancelledError,
          runtime.DeadlineExceededError) as e:
    logging.warning('Failed to get memory usage: %s', e)
    return None


## Handler 
Example 2
Project: luci-py   Author: luci   File: txn.py    Apache License 2.0 5 votes vote down vote up
def transaction_async(callback, **ctx_options):
  """Converts all sorts of random exceptions into CommitError.

  Arguments:
    callback: function to run in the transaction. See
        https://cloud.google.com/appengine/docs/python/ndb/functions for more
        details.
        It is interesting to note that deep down in
        google/appengine/ext/ndb/context.py, Context.transaction() looks at the
        return value of callback(), and if it is an ndb.Future, will
        automatically handle it and return the yielded value.

  Sets retries default value to 1 instead 3 (!)
  """
  ctx_options.setdefault('retries', 1)
  try:
    result = yield ndb.transaction_async(callback, **ctx_options)
    raise ndb.Return(result)
  except (
      datastore_errors.InternalError,
      datastore_errors.Timeout,
      datastore_errors.TransactionFailedError) as e:
    # https://cloud.google.com/appengine/docs/python/datastore/transactions
    # states the result is ambiguous, it could have succeeded.
    logging.info('Transaction likely failed: %s', e)
    raise CommitError(e)
  except (
      apiproxy_errors.CancelledError,
      datastore_errors.BadRequestError,
      RuntimeError) as e:
    logging.info('Transaction failure: %s', e.__class__.__name__)
    raise CommitError(e) 
Example 3
Project: luci-py   Author: luci   File: utils.py    Apache License 2.0 5 votes vote down vote up
def _get_memory_usage():
  """Returns the amount of memory available as an float in MiB."""
  try:
    return apiruntime.runtime.memory_usage().current()
  except (AssertionError,
          apiproxy_errors.CancelledError,
          runtime.DeadlineExceededError) as e:
    logging.warning('Failed to get memory usage: %s', e)
    return None


## Handler 
Example 4
Project: luci-py   Author: luci   File: txn.py    Apache License 2.0 5 votes vote down vote up
def transaction_async(callback, **ctx_options):
  """Converts all sorts of random exceptions into CommitError.

  Arguments:
    callback: function to run in the transaction. See
        https://cloud.google.com/appengine/docs/python/ndb/functions for more
        details.
        It is interesting to note that deep down in
        google/appengine/ext/ndb/context.py, Context.transaction() looks at the
        return value of callback(), and if it is an ndb.Future, will
        automatically handle it and return the yielded value.

  Sets retries default value to 1 instead 3 (!)
  """
  ctx_options.setdefault('retries', 1)
  try:
    result = yield ndb.transaction_async(callback, **ctx_options)
    raise ndb.Return(result)
  except (
      datastore_errors.InternalError,
      datastore_errors.Timeout,
      datastore_errors.TransactionFailedError) as e:
    # https://cloud.google.com/appengine/docs/python/datastore/transactions
    # states the result is ambiguous, it could have succeeded.
    logging.info('Transaction likely failed: %s', e)
    raise CommitError(e)
  except (
      apiproxy_errors.CancelledError,
      datastore_errors.BadRequestError,
      RuntimeError) as e:
    logging.info('Transaction failure: %s', e.__class__.__name__)
    raise CommitError(e) 
Example 5
Project: luci-py   Author: luci   File: utils.py    Apache License 2.0 5 votes vote down vote up
def _get_memory_usage():
  """Returns the amount of memory available as an float in MiB."""
  try:
    return apiruntime.runtime.memory_usage().current()
  except (AssertionError,
          apiproxy_errors.CancelledError,
          runtime.DeadlineExceededError) as e:
    logging.warning('Failed to get memory usage: %s', e)
    return None


## Handler 
Example 6
Project: luci-py   Author: luci   File: utils.py    Apache License 2.0 5 votes vote down vote up
def _get_memory_usage():
  """Returns the amount of memory available as an float in MiB."""
  try:
    return apiruntime.runtime.memory_usage().current()
  except (AssertionError,
          apiproxy_errors.CancelledError,
          runtime.DeadlineExceededError) as e:
    logging.warning('Failed to get memory usage: %s', e)
    return None


## Handler 
Example 7
Project: luci-py   Author: luci   File: txn.py    Apache License 2.0 5 votes vote down vote up
def transaction_async(callback, **ctx_options):
  """Converts all sorts of random exceptions into CommitError.

  Arguments:
    callback: function to run in the transaction. See
        https://cloud.google.com/appengine/docs/python/ndb/functions for more
        details.
        It is interesting to note that deep down in
        google/appengine/ext/ndb/context.py, Context.transaction() looks at the
        return value of callback(), and if it is an ndb.Future, will
        automatically handle it and return the yielded value.

  Sets retries default value to 1 instead 3 (!)
  """
  ctx_options.setdefault('retries', 1)
  try:
    result = yield ndb.transaction_async(callback, **ctx_options)
    raise ndb.Return(result)
  except (
      datastore_errors.InternalError,
      datastore_errors.Timeout,
      datastore_errors.TransactionFailedError) as e:
    # https://cloud.google.com/appengine/docs/python/datastore/transactions
    # states the result is ambiguous, it could have succeeded.
    logging.info('Transaction likely failed: %s', e)
    raise CommitError(e)
  except (
      apiproxy_errors.CancelledError,
      datastore_errors.BadRequestError,
      RuntimeError) as e:
    logging.info('Transaction failure: %s', e.__class__.__name__)
    raise CommitError(e) 
Example 8
Project: luci-py   Author: luci   File: utils.py    Apache License 2.0 5 votes vote down vote up
def _get_memory_usage():
  """Returns the amount of memory available as an float in MiB."""
  try:
    return apiruntime.runtime.memory_usage().current()
  except (AssertionError,
          apiproxy_errors.CancelledError,
          runtime.DeadlineExceededError) as e:
    logging.warning('Failed to get memory usage: %s', e)
    return None


## Handler 
Example 9
Project: luci-py   Author: luci   File: txn.py    Apache License 2.0 5 votes vote down vote up
def transaction_async(callback, **ctx_options):
  """Converts all sorts of random exceptions into CommitError.

  Arguments:
    callback: function to run in the transaction. See
        https://cloud.google.com/appengine/docs/python/ndb/functions for more
        details.
        It is interesting to note that deep down in
        google/appengine/ext/ndb/context.py, Context.transaction() looks at the
        return value of callback(), and if it is an ndb.Future, will
        automatically handle it and return the yielded value.

  Sets retries default value to 1 instead 3 (!)
  """
  ctx_options.setdefault('retries', 1)
  try:
    result = yield ndb.transaction_async(callback, **ctx_options)
    raise ndb.Return(result)
  except (
      datastore_errors.InternalError,
      datastore_errors.Timeout,
      datastore_errors.TransactionFailedError) as e:
    # https://cloud.google.com/appengine/docs/python/datastore/transactions
    # states the result is ambiguous, it could have succeeded.
    logging.info('Transaction likely failed: %s', e)
    raise CommitError(e)
  except (
      apiproxy_errors.CancelledError,
      datastore_errors.BadRequestError,
      RuntimeError) as e:
    logging.info('Transaction failure: %s', e.__class__.__name__)
    raise CommitError(e) 
Example 10
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: logservice.py    Apache License 2.0 4 votes vote down vote up
def _flush(self):
    """Internal version of flush() with no locking."""
    records_to_be_flushed = []
    try:
      while True:
        group = log_service_pb.UserAppLogGroup()
        bytes_left = self._MAX_FLUSH_SIZE
        while self._buffer:
          record = self._get_record()
          if record.IsBlank():
            continue

          message = self._clean(record.message)



          message = self._truncate(message, self._MAX_LINE_SIZE)


          if len(message) > bytes_left:
            self._rollback_record(record)
            break

          records_to_be_flushed.append(record)

          line = group.add_log_line()
          line.set_timestamp_usec(record.created)
          line.set_level(record.level)
          if record.source_location is not None:
            line.mutable_source_location().set_file(record.source_location[0])
            line.mutable_source_location().set_line(record.source_location[1])
            line.mutable_source_location().set_function_name(
                record.source_location[2])
          line.set_message(message)

          bytes_left -= 1 + group.lengthString(line.ByteSize())

        request = log_service_pb.FlushRequest()
        request.set_logs(group.Encode())
        response = api_base_pb.VoidProto()
        apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)
        if not self._buffer:
          break
    except apiproxy_errors.CancelledError:


      records_to_be_flushed.reverse()
      self._buffer.extendleft(records_to_be_flushed)
    except Exception, e:
      records_to_be_flushed.reverse()
      self._buffer.extendleft(records_to_be_flushed)
      line = '-' * 80
      msg = 'ERROR: Could not flush to log_service (%s)\n%s\n%s\n%s\n'




      _sys_stderr.write(msg % (e, line, self._contents(), line))
      self._clear()
      raise