File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -192,9 +192,11 @@ def __getstate__(self):
192
192
for s , d in self .callbacks .items ()},
193
193
# It is simpler to reconstruct this from callbacks in __setstate__.
194
194
"_func_cid_map" : None ,
195
+ "_cid_gen" : next (self ._cid_gen )
195
196
}
196
197
197
198
def __setstate__ (self , state ):
199
+ cid_count = state .pop ('_cid_gen' )
198
200
vars (self ).update (state )
199
201
self .callbacks = {
200
202
s : {cid : _weak_or_strong_ref (func , self ._remove_proxy )
@@ -203,6 +205,7 @@ def __setstate__(self, state):
203
205
self ._func_cid_map = {
204
206
s : {proxy : cid for cid , proxy in d .items ()}
205
207
for s , d in self .callbacks .items ()}
208
+ self ._cid_gen = itertools .count (cid_count )
206
209
207
210
def connect (self , signal , func ):
208
211
"""Register *func* to be called when signal *signal* is generated."""
Original file line number Diff line number Diff line change @@ -209,6 +209,13 @@ def is_not_empty(self):
209
209
assert self .callbacks ._func_cid_map != {}
210
210
assert self .callbacks .callbacks != {}
211
211
212
+ def test_cid_restore (self ):
213
+ cb = cbook .CallbackRegistry ()
214
+ cb .connect ('a' , lambda : None )
215
+ cb2 = pickle .loads (pickle .dumps (cb ))
216
+ cid = cb2 .connect ('c' , lambda : None )
217
+ assert cid == 1
218
+
212
219
@pytest .mark .parametrize ('pickle' , [True , False ])
213
220
def test_callback_complete (self , pickle ):
214
221
# ensure we start with an empty registry
You can’t perform that action at this time.
0 commit comments