本文整理汇总了Python中google.appengine.runtime.DeadlineExceededError方法的典型用法代码示例。如果您正苦于以下问题:Python runtime.DeadlineExceededError方法的具体用法?Python runtime.DeadlineExceededError怎么用?Python runtime.DeadlineExceededError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.runtime
的用法示例。
在下文中一共展示了runtime.DeadlineExceededError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GvizTableData
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def GvizTableData(request):
"""Returns a string formatted for consumption by a Google Viz table."""
#def throw_deadline():
# logging.info('MANUAL THROW!! DeadlineExceededError DeadlineExceededError')
# raise DeadlineExceededError
#t = Timer(15.0, throw_deadline)
test_set = None
category = request.GET.get('category')
if not category:
return http.HttpResponseBadRequest('Must pass category=something')
test_set = all_test_sets.GetTestSet(category)
if not test_set:
return http.HttpResponseBadRequest(
'No test set was found for category=%s' % category)
formatted_gviz_table_data = GetStats(request, test_set, 'gviz_table_data')
return http.HttpResponse(formatted_gviz_table_data)
示例2: generate_edges_page
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [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
示例3: _WaitImpl
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def _WaitImpl(self):
"""Waits on the API call associated with this RPC. The callback,
if provided, will be executed before Wait() returns. If this RPC
is already complete, or if the RPC was never started, this
function will return immediately.
Raises:
InterruptedError if a callback throws an uncaught exception.
"""
try:
rpc_completed = _apphosting_runtime___python__apiproxy.Wait(self)
except (runtime.DeadlineExceededError, apiproxy_errors.InterruptedError):
raise
except:
exc_class, exc, tb = sys.exc_info()
if (isinstance(exc, SystemError) and
exc.args[0] == 'uncaught RPC exception'):
raise
rpc = None
if hasattr(exc, "_appengine_apiproxy_rpc"):
rpc = exc._appengine_apiproxy_rpc
new_exc = apiproxy_errors.InterruptedError(exc, rpc)
raise new_exc.__class__, new_exc, tb
return True
示例4: get
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def get(self):
if self.repo: # Do some counting.
try:
counter = model.Counter.get_unfinished_or_create(
self.repo, self.SCAN_NAME)
entities_remaining = True
while entities_remaining:
# Batch the db updates.
for _ in xrange(100):
entities_remaining = run_count(
self.make_query, self.update_counter, counter)
if not entities_remaining:
break
# And put the updates at once.
counter.put()
except runtime.DeadlineExceededError:
# Continue counting in another task.
self.add_task_for_repo(self.repo, self.SCAN_NAME, self.ACTION)
else: # Launch counting tasks for all repositories.
for repo in model.Repo.list():
self.add_task_for_repo(repo, self.SCAN_NAME, self.ACTION)
示例5: post
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def post(self, request, *args, **kwargs):
del request, args, kwargs # unused
query = model.Person.all(filter_expired=False).filter(
'repo =', self.env.repo)
cursor = self.params.cursor
if cursor:
query.with_cursor(cursor)
try:
for person in query:
next_cursor = query.cursor()
self._check_person(person)
cursor = next_cursor
except runtime.DeadlineExceededError:
self.schedule_task(self.env.repo, cursor=cursor)
except datastore_errors.Timeout:
self.schedule_task(self.env.repo, cursor=cursor)
return django.http.HttpResponse('')
示例6: post
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def post(self, request, *args, **kwargs):
del request, args, kwargs # unused
q = self.get_query()
cursor = self.params.get('cursor', '')
if cursor:
q.with_cursor(cursor)
try:
now = utils.get_utcnow()
for item in q:
next_cursor = q.cursor()
associated_person = model.Person.get(
self.env.repo, self.get_person_record_id(item))
if not associated_person:
if now - self.get_base_timestamp(item) > _STRAY_CLEANUP_TTL:
db.delete(item)
cursor = next_cursor
except runtime.DeadlineExceededError:
self.schedule_task(self.env.repo, cursor=cursor)
except datastore_errors.Timeout:
self.schedule_task(self.env.repo, cursor=cursor)
return django.http.HttpResponse('')
示例7: test_task_rescheduling
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def test_task_rescheduling(self):
"""Tests that task is rescheduled for continuation."""
tq_mock = mox.Mox()
tq_mock.StubOutWithMock(taskqueue, 'add')
taskqueue.add(name=mox.IsA(unicode),
method='POST',
url='/haiti/tasks/process_expirations',
queue_name='expiry',
params={'cursor': ''})
tq_mock.ReplayAll()
# DeadlineExceededErrors can be raised at any time. A convenient way for
# us to raise it during this test execution is with utils.get_utcnow.
with mock.patch('utils.get_utcnow') as get_utcnow_mock:
get_utcnow_mock.side_effect = runtime.DeadlineExceededError()
self.run_task('/haiti/tasks/process_expirations', method='POST')
tq_mock.VerifyAll()
tq_mock.UnsetStubs()
示例8: detect_labels
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def detect_labels(bucket_id, object_id):
"""Detects labels from uploaded image using Vision API."""
try:
# Construct GCS uri path
gcs_image_uri = 'gs://{}/{}'.format(bucket_id, object_id)
# Build request payload dict for label detection
request_dict = [{
'image': {
'source': {
'gcsImageUri': gcs_image_uri
}
},
'features': [{
'type': 'LABEL_DETECTION',
'maxResults': 10,
}]
}]
vision_svc = get_vision_svc()
api_request = vision_svc.images().annotate(body={
'requests': request_dict
})
response = api_request.execute()
labels = []
if 'labelAnnotations' in response['responses'][0]:
labels = response['responses'][0]['labelAnnotations']
return labels
except DeadlineExceededError:
logging.exception('Exceeded deadline in detect_labels()')
示例9: detect_automl_labels
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def detect_automl_labels(bucket_id, object_id):
"""Detects labels from image using AutoML Vision."""
try:
# Read image file contents from GCS
filename = '/{}/{}'.format(bucket_id, object_id)
gcs_file = cloudstorage.open(filename)
encoded_contents = base64.b64encode(gcs_file.read())
gcs_file.close()
# Build request payload dict for label detection
request_dict = {
'payload': {
'image': {
'imageBytes': encoded_contents
}
},
'params': {
'score_threshold': "0.5"
}
}
# Get predictions from the AutoML Vision model
automl_svc = get_automl_svc()
parent = 'projects/{}/locations/us-central1/models/{}'.format(
app_identity.get_application_id(),
current_app.config['AUTOML_MODEL_ID'])
request = automl_svc.projects().locations().models().predict(
name=parent, body=request_dict)
response = request.execute()
return response['payload']
except DeadlineExceededError:
logging.exception('Exceeded deadline in detect_automl_labels()')
示例10: get
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def get(self):
from google.appengine.runtime import DeadlineExceededError
try:
time.sleep(70)
self.response.write('Completed.')
except DeadlineExceededError:
self.response.clear()
self.response.set_status(500)
self.response.out.write(
'The request did not complete in time.')
# [END gae_python_request_timer]
# [START gae_python_environment]
示例11: test_timer
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def test_timer(testbed):
app = webtest.TestApp(main.app)
with mock.patch('main.time.sleep') as sleep_mock:
sleep_mock.side_effect = DeadlineExceededError()
app.get('/timer', status=500)
assert sleep_mock.called
示例12: _get_memory_usage
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def _get_memory_usage():
"""Returns the amount of memory used as an float in MiB."""
try:
return apiruntime.runtime.memory_usage().current()
except (AssertionError,
apiproxy_errors.CancelledError,
apiproxy_errors.DeadlineExceededError,
apiproxy_errors.RPCFailedError,
runtime.DeadlineExceededError) as e:
logging.warning('Failed to get memory usage: %s', e)
return None
## Handler
示例13: report_memory
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def report_memory(app):
"""Wraps an app so handlers log when memory usage increased by at least 0.5MB
after the handler completed.
"""
min_delta = 0.5
old_dispatcher = app.router.dispatch
def dispatch_and_report(*args, **kwargs):
before = _get_memory_usage()
deadline = False
try:
return old_dispatcher(*args, **kwargs)
except runtime.DeadlineExceededError:
# Don't try to call any function after, it'll likely fail anyway. It is
# because _get_memory_usage() does an RPC under the hood.
deadline = True
raise
finally:
if not deadline:
after = _get_memory_usage()
if before and after and after >= before + min_delta:
logging.debug(
'Memory usage: %.1f -> %.1f MB; delta: %.1f MB',
before, after, after-before)
app.router.dispatch = dispatch_and_report
## Time
示例14: cron_delete_old_bot
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def cron_delete_old_bot():
"""Deletes stale BotRoot entity groups."""
start = utils.utcnow()
# Run for 4.5 minutes and schedule the cron job every 5 minutes. Running for
# 9.5 minutes (out of 10 allowed for a cron job) results in 'Exceeded soft
# private memory limit of 512 MB with 512 MB' even if this loop should be
# fairly light on memory usage.
time_to_stop = start + datetime.timedelta(seconds=int(4.5*60))
total = 0
deleted = []
try:
q = BotRoot.query(default_options=ndb.QueryOptions(keys_only=True))
for bot_root_key in q:
# Check if it has any BotEvent left. If not, it means that the entity is
# older than _OLD_BOT_EVENTS_CUF_OFF, so the whole thing can be deleted
# now.
# In particular, ignore the fact that BotInfo may still exist, since if
# there's no BotEvent left, it's probably a broken entity or a forgotten
# dead bot.
if BotEvent.query(ancestor=bot_root_key).count(limit=1):
continue
deleted.append(bot_root_key.string_id())
# Delete the whole group. An ancestor query will retrieve the entity
# itself too, so no need to explicitly delete it.
keys = ndb.Query(ancestor=bot_root_key).fetch(keys_only=True)
ndb.delete_multi(keys)
total += len(keys)
if utils.utcnow() >= time_to_stop:
break
return total
except runtime.DeadlineExceededError:
pass
finally:
logging.info(
'Deleted %d entities from the following bots:\n%s',
total, ', '.join(sorted(deleted)))
示例15: emit
# 需要导入模块: from google.appengine import runtime [as 别名]
# 或者: from google.appengine.runtime import DeadlineExceededError [as 别名]
def emit(self, record):
"""Emit a record.
This implementation is based on the implementation of
StreamHandler.emit().
Args:
record: A Python logging.LogRecord object.
"""
try:
if features.IsEnabled("LogServiceWriteRecord"):
logservice.write_record(self._AppLogsLevel(record.levelno),
record.created,
self.format(record),
self._AppLogsLocation(record))
else:
message = self._AppLogsMessage(record)
if isinstance(message, unicode):
message = message.encode("UTF-8")
logservice.write(message)
except (KeyboardInterrupt, SystemExit, runtime.DeadlineExceededError):
raise
except:
self.handleError(record)