#15156: Pickling with __reduce__() loops creates invalid pickles
-------------------------------------+-------------------------------------
       Reporter:  vbraun             |        Owner:
           Type:  defect             |       Status:  needs_info
       Priority:  major              |    Milestone:  sage-6.3
      Component:  misc               |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  SimonKing,         |    Reviewers:
  jkeitel, novoselt, nbruin          |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:                     |  9e449c3269e35238397a684d3262651b6bd74d51
  u/saraedum/ticket/15156            |     Stopgaps:
   Dependencies:                     |
-------------------------------------+-------------------------------------
Changes (by saraedum):

 * commit:   => 9e449c3269e35238397a684d3262651b6bd74d51


Comment:

 I found this useful to find out which object causes the cyclic reference.
 It traverses the graph which `__reduce__` creates and looks for cycles. It
 is certainly not complete, so I do not want to include it into sage like
 this.
 {{{
 from collections import defaultdict
 graph = {}
 decode_graph = {}
 queue = [o]
 while queue:
     o = queue.pop()
     if id(o) in graph:
         continue
     decode_graph[id(o)] = o
     if isinstance(o, (list, tuple)):
         reduction = (None, list(o))
     elif isinstance(o, dict):
         reduction = (None, list(o.keys()) + list(o.values()))
     elif isinstance(o, (str, int, float)):
         reduction = (None, [])
     else:
         try:
             reduction = o.__reduce_ex__(2)
         except TypeError:
             reduction = (None, [])
     args = reduction[1]
     graph[id(o)] = [id(a) for a in args]
     queue.extend(args)

     if len(reduction) >= 3:
         queue.append(reduction[2])
     if len(reduction) >= 4:
         queue.append(reduction[3])
     if len(reduction) >= 5:
         queue.append(reduction[4])

 from sage.graphs.digraph import DiGraph
 graph = DiGraph(graph)
 for cycle in graph.all_simple_cycles():
     print [decode_graph[i] for i in cycle]
 }}}
 ----
 New commits:
 
||[http://git.sagemath.org/sage.git/commit/?id=98d17b4eb321ba74c85956131aa153120e208c5d
 98d17b4]||{{{Check for invalid pickles in _test_pickling()}}}||
 
||[http://git.sagemath.org/sage.git/commit/?id=9e449c3269e35238397a684d3262651b6bd74d51
 9e449c3]||{{{Fix a circular reference in
 PermutationGroupElement.__reduce__()}}}||

--
Ticket URL: <http://trac.sagemath.org/ticket/15156#comment:10>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to