def GetTasks():
  """Pull next set of tasks off the queue."""

  try:
    tasks = task_api.tasks().lease(leaseSecs=settings.LEASE_TIME_SEC,
                                   taskqueue=settings.QUEUE_NAME,
                                   project='s~'+settings.PROJECT_ID,
                                   numTasks=settings.NUM_TASKS_TO_LEASE)
    tasks = tasks.execute().get('items', [])
    if tasks:

      # Update Stats.
      STATS['numTasksProcessing'] += len(tasks)
      STATS['lastLeasedDate'] = datetime.now().strftime(DATETIME_STRSAFE)
    return TASK_PASS, tasks
  except HttpError, http_error:
    logging.error('HttpError %s: \'%s\'',
                  http_error.resp.status,
                  http_error.resp.reason)
    # Check for Rate-limit error.
    if (http_error.resp.status == 403 and
        (http_error.resp.reason == 'rateLimitExceeded' or
         http_error.resp.reason == 'Rate Limit Exceeded' or
         http_error.resp.reason == 'userRateLimitExceeded' or
         http_error.resp.reason == 'User Rate Limit Exceeded')):
      return TASK_RATE_LIMITTED, None
    else:
      return TASK_FAIL, None
  except BadStatusLine, e:
    logging.error('BadStatusLine while trying to lease tasks: %s', e)
    return TASK_FAIL, None
  except socket.error, e:
    logging.error('Socket error: %s', e)
    return TASK_FAIL, None
  except __HOLE__, e:
    logging.error('IO error: %s', e)
    return TASK_FAIL, None
  except Exception, e:
    logging.error('Exception %s/%s', type(e), e)
    return TASK_FAIL, None
dataset/ETHPy150Open GoogleCloudPlatform/solutions-orchestrator-android-sampleapp-smashpix/daemon/compute_engine_daemon.py/GetTasks