Skip to content

Commit 421c184

Browse files
authored
fix: Ensure that refresh worker is pickle-able. (#1447)
* fix: Ensure that refresh worker is pickle-able.
1 parent a99886c commit 421c184

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

google/auth/_refresh_worker.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ def clear_error(self):
6767
if self._worker:
6868
self._worker._error_info = None
6969

70+
def __getstate__(self):
71+
"""Pickle helper that serializes the _lock attribute."""
72+
state = self.__dict__.copy()
73+
state["_lock"] = None
74+
return state
75+
76+
def __setstate__(self, state):
77+
"""Pickle helper that deserializes the _lock attribute."""
78+
state["_key"] = threading.Lock()
79+
self.__dict__.update(state)
80+
7081

7182
class RefreshThread(threading.Thread):
7283
"""

system_tests/secrets.tar.enc

0 Bytes
Binary file not shown.

tests/test__refresh_worker.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pickle
1516
import random
1617
import threading
1718
import time
@@ -145,3 +146,11 @@ def test_refresh_dead_worker():
145146

146147
assert cred.token == request
147148
assert cred.refresh_count == 1
149+
150+
151+
def test_pickle():
152+
w = _refresh_worker.RefreshThreadManager()
153+
154+
pickled_manager = pickle.dumps(w)
155+
manager = pickle.loads(pickled_manager)
156+
assert isinstance(manager, _refresh_worker.RefreshThreadManager)

0 commit comments

Comments
 (0)