本文整理匯總了Python中google.api_core.exceptions.DeadlineExceeded方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.DeadlineExceeded方法的具體用法?Python exceptions.DeadlineExceeded怎麽用?Python exceptions.DeadlineExceeded使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.api_core.exceptions
的用法示例。
在下文中一共展示了exceptions.DeadlineExceeded方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_synchronous_pull_no_deadline_error_if_no_messages
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_synchronous_pull_no_deadline_error_if_no_messages(
publisher, topic_path, subscriber, subscription_path, cleanup
):
# Make sure the topic and subscription get deleted.
cleanup.append((publisher.delete_topic, topic_path))
cleanup.append((subscriber.delete_subscription, subscription_path))
# Create a topic and subscribe to it.
publisher.create_topic(topic_path)
subscriber.create_subscription(subscription_path, topic_path)
try:
response = subscriber.pull(subscription_path, max_messages=2)
except core_exceptions.DeadlineExceeded:
pytest.fail(
"Unexpected DeadlineExceeded error on synchronous pull when no "
"messages published to the topic."
)
else:
assert list(response.received_messages) == []
示例2: test_update_uptime_config
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_update_uptime_config(capsys):
# create and delete happen in uptime fixture.
new_display_name = random_name(10)
new_uptime_check_path = '/' + random_name(10)
with UptimeFixture() as fixture:
# We sometimes see the permission error saying the resource
# may not exist. Weirdly DeadlineExceeded instnace is raised
# in this case.
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=120)
def call_sample():
snippets.update_uptime_check_config(
fixture.config.name, new_display_name, new_uptime_check_path)
call_sample()
out, _ = capsys.readouterr()
snippets.get_uptime_check_config(fixture.config.name)
out, _ = capsys.readouterr()
assert new_display_name in out
assert new_uptime_check_path in out
示例3: glossary
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def glossary():
"""Get the ID of a glossary available to session (do not mutate/delete)."""
glossary_id = "test-{}".format(uuid.uuid4())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
yield glossary_id
# cleanup
@backoff.on_exception(
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
)
def delete_glossary():
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except NotFound as e:
# Ignoring this case.
print("Got NotFound, detail: {}".format(str(e)))
delete_glossary()
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:23,代碼來源:translate_v3_batch_translate_text_with_glossary_test.py
示例4: glossary
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def glossary():
"""Get the ID of a glossary available to session (do not mutate/delete)."""
glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
yield glossary_id
# cleanup
@backoff.on_exception(
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
)
def delete_glossary():
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except NotFound as e:
# Ignoring this case.
print("Got NotFound, detail: {}".format(str(e)))
delete_glossary()
示例5: test_create_glossary
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_create_glossary(capsys):
try:
glossary_id = "test-{}".format(uuid.uuid4())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
out, _ = capsys.readouterr()
# assert
assert "Created:" in out
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
finally:
# cleanup
@backoff.on_exception(
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
)
def delete_glossary():
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except NotFound as e:
# Ignoring this case.
print("Got NotFound, detail: {}".format(str(e)))
delete_glossary()
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:25,代碼來源:translate_v3_create_glossary_test.py
示例6: ingest
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def ingest(self, queue: Queue) -> None:
topic = f'projects/{self.project_id}/topics/{self.topic}'
subscription = f'projects/{self.project_id}/subscriptions/{self.subscription}'
self._ingest_connect(subscription, topic)
self.log.info(f'Monitoring {subscription} subscription for messages...')
while True:
try:
messages = self.ingest_client.pull(
subscription,
max_messages=self.max_messages,
return_immediately=False,
)
for msg in messages.received_messages:
await queue.put(json.loads(msg.message.data.decode()))
self.ingest_client.acknowledge(subscription, [msg.ack_id])
except DeadlineExceeded:
self.log.debug(
f'Reconnecting to {subscription} subscription for messages...'
)
self._ingest_connect(subscription, topic)
示例7: test_fetch_w_absurdly_short_timeout
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_fetch_w_absurdly_short_timeout(ds_entity):
for i in range(5):
entity_id = test_utils.system.unique_resource_id()
ds_entity(KIND, entity_id, foo=i)
class SomeKind(ndb.Model):
foo = ndb.IntegerProperty()
query = SomeKind.query()
timeout = 1e-9 # One nanosecend
with pytest.raises(Exception) as error_context:
query.fetch(timeout=timeout)
assert isinstance(error_context.value, core_exceptions.DeadlineExceeded)
示例8: test_writes
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_writes(capsys, table_id):
# `row.commit()` sometimes ends up with DeadlineExceeded, so now
# we put retries with a hard deadline.
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_simple():
write_simple(PROJECT, BIGTABLE_INSTANCE, table_id)
_write_simple()
out, _ = capsys.readouterr()
assert 'Successfully wrote row' in out
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_increment():
write_increment(PROJECT, BIGTABLE_INSTANCE, table_id)
_write_increment()
out, _ = capsys.readouterr()
assert 'Successfully updated row' in out
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_conditional():
write_conditional(PROJECT, BIGTABLE_INSTANCE, table_id)
_write_conditional()
out, _ = capsys.readouterr()
assert 'Successfully updated row\'s os_name' in out
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
def _write_batch():
write_batch(PROJECT, BIGTABLE_INSTANCE, table_id)
_write_batch()
out, _ = capsys.readouterr()
assert 'Successfully wrote 2 rows' in out
示例9: retry_on_exceptions
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def retry_on_exceptions(exception):
return isinstance(
exception, (Aborted, ServiceUnavailable, DeadlineExceeded))
示例10: test_vision_object_detection_predict
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_vision_object_detection_predict(capsys, verify_model_state):
file_path = "resources/salad.jpg"
# Retry the sample upon DeadlineExceeded, with a hard deadline of 5 mins.
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=300)
def run_sample():
vision_object_detection_predict.predict(PROJECT_ID, MODEL_ID, file_path)
run_sample()
out, _ = capsys.readouterr()
assert "Predicted class name:" in out
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:13,代碼來源:vision_object_detection_predict_test.py
示例11: test_retry_bubble
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_retry_bubble(echo):
with pytest.raises(exceptions.DeadlineExceeded):
echo.echo({
'error': {
'code': code_pb2.Code.Value('DEADLINE_EXCEEDED'),
'message': 'This took longer than you said it should.',
},
})
示例12: test_retry_bubble_async
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import DeadlineExceeded [as 別名]
def test_retry_bubble_async(async_echo):
with pytest.raises(exceptions.DeadlineExceeded):
await async_echo.echo({
'error': {
'code': code_pb2.Code.Value('DEADLINE_EXCEEDED'),
'message': 'This took longer than you said it should.',
},
})