Changeset b53e1fc for fedd


Ignore:
Timestamp:
May 25, 2010 10:50:01 AM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
da2208a
Parents:
75720ab
Message:

Added a routine for finding pickling problems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/util.py

    r75720ab rb53e1fc  
    44import string
    55import logging
     6import pickle
    67
    78import httplib
     
    260261        else:
    261262            return base
     263
     264def find_pickle_problem(o, st=None):
     265    """
     266    Debugging routine to figure out what doesn't pickle from a dict full of
     267    dicts and lists.  It tries to walk down the lists and dicts and pickle each
     268    atom.  If something fails to pickle, it prints an approximation of a stack
     269    trace through the data structure.
     270    """
     271    if st is None: st = [ ]
     272
     273    if isinstance(o, dict):
     274        for k, i in o.items():
     275            st.append(k)
     276            find_pickle_problem(i, st)
     277            st.pop()
     278    elif isinstance(o, list):
     279        st.append('list')
     280        for i in o:
     281            find_pickle_problem(i, st)
     282        st.pop()
     283    else:
     284        try:
     285            pickle.dumps(o)
     286        except pickle.PicklingError, e:
     287            print >>sys.stderr, "<PicklingError>"
     288            print >>sys.stderr, st
     289            print >>sys.stderr, o
     290            print >>sys.stderr, e
     291            print >>sys.stderr, "</PicklingError>"
     292
Note: See TracChangeset for help on using the changeset viewer.