@@ -150,29 +150,18 @@ def h(exc):
150
150
"""
151
151
152
152
# 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}
156
155
157
156
def __init__ (self , exception_handler = _exception_printer ):
158
157
self .exception_handler = exception_handler
159
158
self .callbacks = {}
160
159
self ._cid_gen = itertools .count ()
161
160
self ._func_cid_map = {}
162
161
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
-
171
162
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" : {}}
176
165
177
166
def connect (self , s , func ):
178
167
"""Register *func* to be called when signal *s* is generated.
0 commit comments