@@ -150,29 +150,18 @@ def h(exc):
150150 """
151151
152152 # We maintain two mappings:
153- # callbacks: signal -> {cid -> callback}
154- # _func_cid_map: signal -> {callback -> cid}
155- # (actually, callbacks are weakrefs to the actual callbacks).
153+ # callbacks: signal -> {cid -> weakref-to-callback}
154+ # _func_cid_map: signal -> {weakref-to-callback -> cid}
156155
157156 def __init__ (self , exception_handler = _exception_printer ):
158157 self .exception_handler = exception_handler
159158 self .callbacks = {}
160159 self ._cid_gen = itertools .count ()
161160 self ._func_cid_map = {}
162161
163- # In general, callbacks may not be pickled; thus, we simply recreate an
164- # empty dictionary at unpickling. In order to ensure that `__setstate__`
165- # (which just defers to `__init__`) is called, `__getstate__` must
166- # return a truthy value (for pickle protocol>=3, i.e. Py3, the
167- # *actual* behavior is that `__setstate__` will be called as long as
168- # `__getstate__` does not return `None`, but this is undocumented -- see
169- # http://bugs.python.org/issue12290).
170-
171162 def __getstate__ (self ):
172- return {'exception_handler' : self .exception_handler }
173-
174- def __setstate__ (self , state ):
175- self .__init__ (** state )
163+ # In general, callbacks may not be pickled, so we just drop them.
164+ return {** vars (self ), "callbacks" : {}, "_func_cid_map" : {}}
176165
177166 def connect (self , s , func ):
178167 """Register *func* to be called when signal *s* is generated.
0 commit comments