File: chain.txt

package info (click to toggle)
objgraph 3.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,224 kB
  • sloc: python: 1,188; makefile: 108; sh: 8
file content (26 lines) | stat: -rw-r--r-- 890 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Graph searches
--------------

The other day I was wondering why pickling a particular object errored out
with an error deep in one of the subobjects.

    >>> class MyUnpicklableObject(object):
    ...     def __getstate__(self):
    ...         raise NotImplementedError
    ...
    >>> my_object = dict(foo=dict(unrelated='things'),
    ...                  bar=[dict(nesting='fun'),
    ...                       dict(boobytrap=MyUnpicklableObject())])
    >>> import objgraph
    >>> objgraph.show_chain(
    ...     objgraph.find_ref_chain(
    ...         my_object,
    ...         lambda x: isinstance(x, MyUnpicklableObject)),
    ...     backrefs=False,
    ...     filename='forward-chain.png')
    Graph written to ...dot (4 nodes)
    Image generated as forward-chain.png

.. figure:: chain.png
   :alt: [chain of references from my_object to a MyUnpicklableObject instance]