Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
RetryParams クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
RetryParams
は、src/cloudstorage
に含まれている Cloud Storage 用 App Engine クライアント ライブラリにより提供されます。このクラスを使用すると、タイムアウトおよび再試行を処理するためのデフォルト設定を変更できます。
はじめに
Google Cloud Storage サーバーとの接続が試みられている間、Cloud Storage 用 App Engine クライアント ライブラリは、タイムアウトと再試行の処理にデフォルトの設定を使用します。このクラスを使用すると、アプリケーション全体に対して、またはライブラリ関数(copy2
、delete
、listbucket
、open
、stat
)の特定の呼び出しに対してそれらの設定を変更できます。他のすべての設定は、明示的に上書きされない限り保持されるため、必要な特定の設定のみを変更する必要があります。各 RetryParams
インスタンスは、スレッドごと、リクエストごとに一意です。
アプリケーション全体でデフォルト設定を変更するには、次のように変更する設定をすべて指定して RetryParams
オブジェクトを作成し、このオブジェクトを cloudstorage.set_default_retry_params()
関数に渡します。
my_default_retry_params = cloudstorage.RetryParams(initial_delay=0.2,
max_delay=5.0,
backoff_factor=2,
max_retry_period=15)
cloudstorage.set_default_retry_params(my_default_retry_params)
特定の関数呼び出しのデフォルト設定のみを変更するには、次のように RetryParams
オブジェクトを作成し、retry_params
パラメータで関数に直接渡します。
write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1)
gcs_file = cloudstorage.open(filename,
'w',
content_type='text/plain',
options={'x-goog-meta-foo': 'foo',
'x-goog-meta-bar': 'bar'},
retry_params=write_retry_params)
この方法では、アプリや他の関数呼び出しで使用されるデフォルト設定は、影響を受けません。
インスタンス プロパティ
RetryParams
インスタンスには次のプロパティがあります。
- initial_delay
- 再試行までの遅延時間(秒)。デフォルトは
0.1
です。この遅延は、Google Cloud Storage サーバーの負荷の分散に役立ちます。 - backoff_factor
- 指数バックオフ乗数。最適な処理速度を決定するために使われます。デフォルトは
2.0
です。この値の設定に関するの説明と推奨事項については、バックオフに関する Google Cloud Storage ドキュメントをご覧ください。 - max_delay
- 次の再試行まで待機する最大秒数。デフォルトは
10.0
です。
- min_retries
- 再試行の最小回数。デフォルトは
3
です。
- max_retries
- 再試行の最大回数。まったく再試行しない場合は、この値を 0 に設定します。デフォルトは
6
です。
- max_retry_period
- 特定のリクエストで再試行全体に使用できる最大秒数。デフォルトは
30.0
です。この期間が経過し、かつ、min_retries
回の試行が済んでいる場合、再試行は停止します。 - urlfetch_timeout
- UrlFetch が Google Cloud Storage サーバーとの通信を待機する秒数。これを経過するとタイムアウト エラーが返されます。デフォルトでは、
None
に設定されます。その場合は、デフォルトの UrlFetch 期限(5 秒)が使用されます。最大 60 秒までの範囲で、この値を任意の値に設定できます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[[["\u003cp\u003e\u003ccode\u003eRetryParams\u003c/code\u003e allows customization of timeout and retry settings for the App Engine client library's interactions with Cloud Storage.\u003c/p\u003e\n"],["\u003cp\u003eYou can adjust settings such as \u003ccode\u003einitial_delay\u003c/code\u003e, \u003ccode\u003ebackoff_factor\u003c/code\u003e, \u003ccode\u003emax_delay\u003c/code\u003e, \u003ccode\u003emin_retries\u003c/code\u003e, \u003ccode\u003emax_retries\u003c/code\u003e, \u003ccode\u003emax_retry_period\u003c/code\u003e, and \u003ccode\u003eurlfetch_timeout\u003c/code\u003e to control retry behavior.\u003c/p\u003e\n"],["\u003cp\u003eSettings can be changed application-wide using \u003ccode\u003ecloudstorage.set_default_retry_params()\u003c/code\u003e or for specific function calls by providing \u003ccode\u003eretry_params\u003c/code\u003e to the function directly.\u003c/p\u003e\n"],["\u003cp\u003eEach \u003ccode\u003eRetryParams\u003c/code\u003e instance is specific to a thread and request, allowing for granular control over retries without affecting other parts of the application.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eurlfetch_timeout\u003c/code\u003e setting lets users determine how many seconds to wait for UrlFetch to contact the Cloud Storage servers, defaulting to 5 seconds, but going as high as 60 seconds.\u003c/p\u003e\n"]]],[],null,["# The RetryParams Class\n\n`RetryParams` is provided by the App Engine client library for Cloud Storage contained\nin `src/cloudstorage`. This class lets you change default settings used to\nhandle timeouts and retries.\n\nIntroduction\n------------\n\nThe App Engine client library for Cloud Storage uses default settings for handling\ntimeouts and retries during attempts to contact Google Cloud Storage servers.\nThis class allows you to change those settings, either on an application-wide\nbasis, or for a specific invocation of a library\nfunction (`copy2`, `delete`, `listbucket`, `open`, `stat`). You need change only\nthe specific setting you are interested in, as all other settings are retained\nunless explicitly overwritten. Each `RetryParams` instance is unique per thread\nand per request.\n\nTo change a default setting application-wide, you create a `RetryParams`\nobject, specify whatever settings you wish to change, and supply this object to\nthe `cloudstorage.set_default_retry_params()` function as follows: \n\n my_default_retry_params = cloudstorage.RetryParams(initial_delay=0.2,\n max_delay=5.0,\n backoff_factor=2,\n max_retry_period=15)\n cloudstorage.set_default_retry_params(my_default_retry_params)\n\nTo change default settings for a specific function invocation only, create\na `RetryParams` object and supply it directly to the function in its\n`retry_params` parameter, as follows: \n\n write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1)\n gcs_file = cloudstorage.open(filename,\n 'w',\n content_type='text/plain',\n options={'x-goog-meta-foo': 'foo',\n 'x-goog-meta-bar': 'bar'},\n retry_params=write_retry_params)\n\nThis has no effect on the default settings used by the app or by other\nfunction invocations.\n\nInstance properties\n-------------------\n\nA `RetryParams` instance has the following properties:\n\ninitial_delay\n: The number of seconds to delay before a retry. Default is `0.1`. Delay helps\n distribute load at the Google Cloud Storage server.\n\nbackoff_factor\n: The exponential back-off multiplier, used to determine optimal processing\n rate. Default is `2.0`. For a description and recommendations for setting this\n value, see the Google Cloud Storage documentation on [backoff](/storage/docs/exponential-backoff).\n\nmax_delay\n: The maximum number of seconds to wait between retries. Default is `10.0`.\n\nmin_retries\n: The minimum number of times to retry. Default is `3`.\n\nmax_retries\n: The maximum number of times to retry. Set this value to 0 if\n you don't want any retries. Default is `6`.\n\nmax_retry_period\n: The maximum number of seconds that can be spent on all retries of a\n given request. Default is `30.0`. Retry stops when this period passed AND\n `min_retries` has been attempted.\n\nurlfetch_timeout\n: The number of seconds to wait for UrlFetch to contact the\n Google Cloud Storage servers before returning a timeout error. By default,\n this is set to `None`, which means use the [default UrlFetch deadline](/appengine/docs/legacy/standard/python/issue-requests),\n which is five seconds. You can set this to any value up to a maximum of 60\n seconds."]]