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):
192192 for s , d in self .callbacks .items ()},
193193 # It is simpler to reconstruct this from callbacks in __setstate__.
194194 "_func_cid_map" : None ,
195+ "_cid_gen" : next (self ._cid_gen )
195196 }
196197
197198 def __setstate__ (self , state ):
199+ cid_count = state .pop ('_cid_gen' )
198200 vars (self ).update (state )
199201 self .callbacks = {
200202 s : {cid : _weak_or_strong_ref (func , self ._remove_proxy )
@@ -203,6 +205,7 @@ def __setstate__(self, state):
203205 self ._func_cid_map = {
204206 s : {proxy : cid for cid , proxy in d .items ()}
205207 for s , d in self .callbacks .items ()}
208+ self ._cid_gen = itertools .count (cid_count )
206209
207210 def connect (self , signal , func ):
208211 """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):
209209 assert self .callbacks ._func_cid_map != {}
210210 assert self .callbacks .callbacks != {}
211211
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+
212219 @pytest .mark .parametrize ('pickle' , [True , False ])
213220 def test_callback_complete (self , pickle ):
214221 # ensure we start with an empty registry
You can’t perform that action at this time.
0 commit comments