File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -481,13 +481,18 @@ def __init__(self):
481
481
self ._cid = 0
482
482
self ._func_cid_map = {}
483
483
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
+
484
492
def __getstate__ (self ):
485
- # We cannot currently pickle the callables in the registry, so
486
- # return an empty dictionary.
487
- return {}
493
+ return True
488
494
489
495
def __setstate__ (self , state ):
490
- # re-initialise an empty callback registry
491
496
self .__init__ ()
492
497
493
498
def connect (self , s , func ):
Original file line number Diff line number Diff line change 1
1
from __future__ import (absolute_import , division , print_function ,
2
2
unicode_literals )
3
3
import itertools
4
+ import pickle
4
5
from weakref import ref
5
6
import warnings
6
7
@@ -331,6 +332,10 @@ def test_callback_complete(self):
331
332
def dummy (self ):
332
333
pass
333
334
335
+ def test_pickling (self ):
336
+ assert hasattr (pickle .loads (pickle .dumps (cbook .CallbackRegistry ())),
337
+ "callbacks" )
338
+
334
339
335
340
def _kwarg_norm_helper (inp , expected , kwargs_to_norm , warn_count = 0 ):
336
341
You can’t perform that action at this time.
0 commit comments