Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simplify CallbackRegistry pickling.#16219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 1 commit intomatplotlib:masterfromanntzer:crpickle
Mar 9, 2020
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletionslib/matplotlib/cbook/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,29 +151,18 @@ def h(exc):
"""

# We maintain two mappings:
# callbacks: signal -> {cid -> callback}
# _func_cid_map: signal -> {callback -> cid}
# (actually, callbacks are weakrefs to the actual callbacks).
# callbacks: signal -> {cid -> weakref-to-callback}
# _func_cid_map: signal -> {weakref-to-callback -> cid}

def __init__(self, exception_handler=_exception_printer):
self.exception_handler = exception_handler
self.callbacks = {}
self._cid_gen = itertools.count()
self._func_cid_map = {}

# In general, callbacks may not be pickled; thus, we simply recreate an
# empty dictionary at unpickling. In order to ensure that `__setstate__`
# (which just defers to `__init__`) is called, `__getstate__` must
# return a truthy value (for pickle protocol>=3, i.e. Py3, the
# *actual* behavior is that `__setstate__` will be called as long as
# `__getstate__` does not return `None`, but this is undocumented -- see
# http://bugs.python.org/issue12290).

def __getstate__(self):
return {'exception_handler': self.exception_handler}

def __setstate__(self, state):
self.__init__(**state)
# In general, callbacks may not be pickled, so we just drop them.
return {**vars(self), "callbacks": {}, "_func_cid_map": {}}

def connect(self, s, func):
"""Register *func* to be called when signal *s* is generated.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp