當前位置: 首頁>>代碼示例>>Python>>正文


Python db.Timeout方法代碼示例

本文整理匯總了Python中google.appengine.ext.db.Timeout方法的典型用法代碼示例。如果您正苦於以下問題:Python db.Timeout方法的具體用法?Python db.Timeout怎麽用?Python db.Timeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.ext.db的用法示例。


在下文中一共展示了db.Timeout方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: flush

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def flush(self):
    """Force a flush."""
    if not self.items:
      return

    retry = 0
    options = {"deadline": DATASTORE_DEADLINE}
    while retry <= self.__timeout_retries:
      try:
        self.__flush_function(self.items, options)
        self.clear()
        break
      except db.Timeout, e:
        logging.warning(e)
        logging.warning("Flushing '%s' timed out. Will retry for the %s time.",
                        self, retry)
        retry += 1
        options["deadline"] *= 2
      except apiproxy_errors.RequestTooLargeError:
        self._log_largest_items()
        raise 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:23,代碼來源:context.py

示例2: generate_edges_page

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def generate_edges_page(ndb_iter, page_size, keys_only, edge_type):
    edges = []
    timeouts = 0
    while len(edges) < page_size:
        try:
            entity = ndb_iter.next()
        except StopIteration:
            break
        except Timeout:
            timeouts += 1
            if timeouts > 2:
                break

            continue
        except DeadlineExceededError:
            break

        if keys_only:
            # entity is actualy an ndb.Key and we need to create an empty entity to hold it
            entity = edge_type._meta.fields['node']._type._meta.model(key=entity)

        edges.append(edge_type(node=entity, cursor=ndb_iter.cursor_after().urlsafe()))

    return edges 
開發者ID:graphql-python,項目名稱:graphene-gae,代碼行數:26,代碼來源:fields.py

示例3: DataDumpKeys

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def DataDumpKeys(request):
  """This is used by bin/data_dump.py to get ResultParent keys."""
  bookmark = request.REQUEST.get('bookmark')
  model_name = request.REQUEST.get('model')
  count = int(request.REQUEST.get('count', 0))
  fetch_limit = int(request.REQUEST.get('fetch_limit', 999))
  created_str = request.REQUEST.get('created', 0)
  created = None
  if created_str:
    created = datetime.datetime.strptime(created_str, '%Y-%m-%d %H:%M:%S')
  models = {
      'UserAgent': UserAgent,
      'ResultParent': ResultParent,
      'ResultTime': ResultTime,
      }
  model = models.get(model_name, UserAgent)
  query = pager.PagerQuery(model, keys_only=True)
  if created:
    query.filter('created >=', created)
    query.order('created')
  try:
    prev_bookmark, results, next_bookmark = query.fetch(fetch_limit, bookmark)
  except db.Timeout:
    logging.warn('db.Timeout during initial fetch.')
    return http.HttpResponseServerError('db.Timeout during initial fetch.')
  response_params = {
      'bookmark': next_bookmark,
      'model': model_name,
      'count': count + len(results),
      'keys': [str(key) for key in results]
      }
  if created_str:
    response_params['created'] = created_str
  return http.HttpResponse(content=simplejson.dumps(response_params),
                           content_type='application/json') 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:37,代碼來源:admin.py

示例4: UpdateStatsCache

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def UpdateStatsCache(cls, category, browsers):
        """Update the memcache of stats for all the tests for each browser.

        This is also where the summary stats get updated.

        Args:
            category: a category string like 'network'
            browsers: a list of browsers like ['Firefox 3.6', 'IE 8.0']
        Returns:
            a list of browsers that were not processed due to a timeout.
        """
        test_set = all_test_sets.GetTestSet(category)
        test_keys = [t.key for t in test_set.VisibleTests()]
        ua_stats = {}
        unhandled_browsers = []
        is_timed_out = False
        for browser in browsers:
            try:
                medians, num_scores = test_set.GetMediansAndNumScores(browser)
            except db.Timeout:
                is_timed_out = True
            if is_timed_out:
                logging.info('Timed out \'%s\' in UpdateStatsCache doing '
                                         'GetMediansAndNumScores for %s', category, browser)
                unhandled_browsers.append(browser)
            else:
                stats = test_set.GetStats(test_keys, medians, num_scores)
                ua_stats[browser] = stats
        memcache.set_multi(ua_stats, **cls.MemcacheParams(category))
        if not is_timed_out:
            SummaryStatsManager.UpdateStats(category, ua_stats)
        return unhandled_browsers 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:34,代碼來源:result_stats.py

示例5: put

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def put(self):
        count = 0
        while count < 3:
            try:
                return db.Model.put(self)
            except db.Timeout:
                count += 1
        else:
            raise db.Timeout() 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:11,代碼來源:rotmodel.py

示例6: flush_function

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def flush_function(self, items, options):
    FlushFunction.calls.append((items, dict(options)))
    if len(FlushFunction.calls) <= FlushFunction.timeouts:
      raise db.Timeout()
    FlushFunction.persistent_storage.extend(items)

  # pylint: disable=unused-argument 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:9,代碼來源:context_test.py

示例7: testFlushTimeoutTooManyTimes

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def testFlushTimeoutTooManyTimes(self):
    FlushFunction.timeouts = context._ItemList.DEFAULT_RETRIES + 1
    self.list.append('abc')
    self.assertRaises(db.Timeout, self.list.flush)
    self.assertEqual(context._ItemList.DEFAULT_RETRIES + 1,
                     len(FlushFunction.calls)) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:8,代碼來源:context_test.py

示例8: UploadRankers

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def UploadRankers(request):
  """Rebuild rankers."""
  time_limit = int(request.REQUEST.get('time_limit', 8))
  category = request.REQUEST.get('category')
  params_str = request.REQUEST.get('params_str')
  test_key_browsers_json = request.REQUEST.get('test_key_browsers_json')
  ranker_values_json = request.REQUEST.get('ranker_values_json')

  if not category:
    return http.HttpResponseServerError('Must send "category".')
  if not test_key_browsers_json:
    return http.HttpResponseServerError('Must send "test_key_browsers_json".')
  if not ranker_values_json:
    return http.HttpResponseServerError('Must send "ranker_values_json".')

  test_key_browsers = simplejson.loads(test_key_browsers_json)
  ranker_values = simplejson.loads(ranker_values_json)
  start_time = time.clock()

  message = None
  test_set = all_test_sets.GetTestSet(category)
  test_browsers = [(test_set.GetTest(test_key), browser)
                   for test_key, browser in test_key_browsers]
  rankers = result_ranker.GetOrCreateRankers(test_browsers, params_str)

  for ranker, (median, num_scores, values_str) in zip(rankers, ranker_values):
    if time.clock() - start_time > time_limit:
      message = 'Over time limit'
      break
    if ranker.GetMedianAndNumScores() == (median, num_scores):
      logging.info('Skipping ranker with unchanged values: %s',
                   ranker.key().name())
      continue
    values = map(int, values_str.split('|'))
    try:
      ranker.SetValues(values, num_scores)
    except db.Timeout:
      message = 'db.Timeout'
      break
  response_params = {}
  if message:
    logging.info('message: %s', message)
    response_params['message'] = message
  return http.HttpResponse(simplejson.dumps(response_params)) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:46,代碼來源:admin_rankers.py

示例9: PerformWork

# 需要導入模塊: from google.appengine.ext import db [as 別名]
# 或者: from google.appengine.ext.db import Timeout [as 別名]
def PerformWork(self, thread_pool):
    """Perform the work of this work item and report the results.

    Args:
      thread_pool: An AdaptiveThreadPool instance.

    Returns:
      A tuple (status, instruction) of the work status and an instruction
      for the ThreadGate.
    """
    status = adaptive_thread_pool.WorkItem.FAILURE
    instruction = adaptive_thread_pool.ThreadGate.DECREASE


    try:
      self.MarkAsTransferring()



      try:
        transfer_time = self._TransferItem(thread_pool)
        if transfer_time is None:
          status = adaptive_thread_pool.WorkItem.RETRY
          instruction = adaptive_thread_pool.ThreadGate.HOLD
        else:
          logger.debug('[%s] %s Transferred %d entities in %0.1f seconds',
                       threading.currentThread().getName(), self, self.count,
                       transfer_time)
          sys.stdout.write('.')
          sys.stdout.flush()
          status = adaptive_thread_pool.WorkItem.SUCCESS
          if transfer_time <= MAXIMUM_INCREASE_DURATION:
            instruction = adaptive_thread_pool.ThreadGate.INCREASE
          elif transfer_time <= MAXIMUM_HOLD_DURATION:
            instruction = adaptive_thread_pool.ThreadGate.HOLD
      except (db.InternalError, db.NotSavedError, db.Timeout,
              db.TransactionFailedError,
              apiproxy_errors.OverQuotaError,
              apiproxy_errors.DeadlineExceededError,
              apiproxy_errors.ApplicationError), e:

        status = adaptive_thread_pool.WorkItem.RETRY
        logger.exception('Retrying on non-fatal datastore error: %s', e)
      except urllib2.HTTPError, e:
        http_status = e.code
        if http_status >= 500 and http_status < 600:

          status = adaptive_thread_pool.WorkItem.RETRY
          logger.exception('Retrying on non-fatal HTTP error: %d %s',
                           http_status, e.msg)
        else:
          self.SetError()
          status = adaptive_thread_pool.WorkItem.FAILURE 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:55,代碼來源:bulkloader.py


注:本文中的google.appengine.ext.db.Timeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。