File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff 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
7182class RefreshThread (threading .Thread ):
7283 """
Original file line number Diff line number Diff line change 1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import pickle
1516import random
1617import threading
1718import 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 )
You can’t perform that action at this time.
0 commit comments