Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita5604a5

Browse files
authored
fix: resolve the issue where rpc timeout of 0 is used when timeout expires (#776)
* fix: resolve the issue where rpc timeout of 0 is used when timeout expires* address offline feedback* formatting* update comment
1 parentb1fae31 commita5604a5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

‎google/api_core/timeout.py‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ def __call__(self, func):
102102
deffunc_with_timeout(*args,**kwargs):
103103
"""Wrapped function that adds timeout."""
104104

105-
remaining_timeout=self._timeout
106-
ifremaining_timeoutisnotNone:
105+
ifself._timeoutisnotNone:
107106
# All calculations are in seconds
108107
now_timestamp=self._clock().timestamp()
109108

@@ -114,8 +113,19 @@ def func_with_timeout(*args, **kwargs):
114113
now_timestamp=first_attempt_timestamp
115114

116115
time_since_first_attempt=now_timestamp-first_attempt_timestamp
117-
# Avoid setting negative timeout
118-
kwargs["timeout"]=max(0,self._timeout-time_since_first_attempt)
116+
remaining_timeout=self._timeout-time_since_first_attempt
117+
118+
# Although the `deadline` parameter in `google.api_core.retry.Retry`
119+
# is deprecated, and should be treated the same as the `timeout`,
120+
# it is still possible for the `deadline` argument in
121+
# `google.api_core.retry.Retry` to be larger than the `timeout`.
122+
# See https://github.com/googleapis/python-api-core/issues/654
123+
# Only positive non-zero timeouts are supported.
124+
# Revert back to the initial timeout for negative or 0 timeout values.
125+
ifremaining_timeout<1:
126+
remaining_timeout=self._timeout
127+
128+
kwargs["timeout"]=remaining_timeout
119129

120130
returnfunc(*args,**kwargs)
121131

‎tests/unit/test_timeout.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def _clock():
8484
wrapped()
8585
target.assert_called_with(timeout=3.0)
8686
wrapped()
87-
target.assert_called_with(timeout=0.0)
87+
target.assert_called_with(timeout=42.0)
8888
wrapped()
89-
target.assert_called_with(timeout=0.0)
89+
target.assert_called_with(timeout=42.0)
9090

9191
deftest_apply_no_timeout(self):
9292
target=mock.Mock(spec=["__call__","__name__"],__name__="target")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp