File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -481,13 +481,18 @@ def __init__(self):
481481 self ._cid = 0
482482 self ._func_cid_map = {}
483483
484+ # In general, callbacks may not be pickled; thus, we simply recreate an
485+ # empty dictionary at unpickling. In order to ensure that `__setstate__`
486+ # (which just defers to `__init__`) is called, `__getstate__` must
487+ # return a truthy value (for pickle protocol>=3, i.e. Py3, the
488+ # *actual* behavior is that `__setstate__` will be called as long as
489+ # `__getstate__` does not return `None`, but this is undocumented -- see
490+ # http://bugs.python.org/issue12290).
491+
484492 def __getstate__ (self ):
485- # We cannot currently pickle the callables in the registry, so
486- # return an empty dictionary.
487- return {}
493+ return True
488494
489495 def __setstate__ (self , state ):
490- # re-initialise an empty callback registry
491496 self .__init__ ()
492497
493498 def connect (self , s , func ):
Original file line number Diff line number Diff line change 11from __future__ import (absolute_import , division , print_function ,
22 unicode_literals )
33import itertools
4+ import pickle
45from weakref import ref
56import warnings
67
@@ -331,6 +332,10 @@ def test_callback_complete(self):
331332 def dummy (self ):
332333 pass
333334
335+ def test_pickling (self ):
336+ assert hasattr (pickle .loads (pickle .dumps (cbook .CallbackRegistry ())),
337+ "callbacks" )
338+
334339
335340def _kwarg_norm_helper (inp , expected , kwargs_to_norm , warn_count = 0 ):
336341
You can’t perform that action at this time.
0 commit comments