You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

4 years ago
  1. #!/home/alpcentaur/ProjektA/PrototypeWebApp/venv/bin/python3.5
  2. #
  3. # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
  4. # Copyright (c) 2008-2016 California Institute of Technology.
  5. # Copyright (c) 2016-2018 The Uncertainty Quantification Foundation.
  6. # License: 3-clause BSD. The full license text is available at:
  7. # - https://github.com/uqfoundation/dill/blob/master/LICENSE
  8. """
  9. display the reference paths for objects in ``dill.types`` or a .pkl file
  10. Notes:
  11. the generated image is useful in showing the pointer references in
  12. objects that are or can be pickled. Any object in ``dill.objects``
  13. listed in ``dill.load_types(picklable=True, unpicklable=True)`` works.
  14. Examples::
  15. $ get_objgraph FrameType
  16. Image generated as FrameType.png
  17. """
  18. import dill as pickle
  19. #pickle.debug.trace(True)
  20. #import pickle
  21. # get all objects for testing
  22. from dill import load_types
  23. load_types(pickleable=True,unpickleable=True)
  24. from dill import objects
  25. if __name__ == "__main__":
  26. import sys
  27. if len(sys.argv) != 2:
  28. print ("Please provide exactly one file or type name (e.g. 'IntType')")
  29. msg = "\n"
  30. for objtype in list(objects.keys())[:40]:
  31. msg += objtype + ', '
  32. print (msg + "...")
  33. else:
  34. objtype = str(sys.argv[-1])
  35. try:
  36. obj = objects[objtype]
  37. except KeyError:
  38. obj = pickle.load(open(objtype,'rb'))
  39. import os
  40. objtype = os.path.splitext(objtype)[0]
  41. try:
  42. import objgraph
  43. objgraph.show_refs(obj, filename=objtype+'.png')
  44. except ImportError:
  45. print ("Please install 'objgraph' to view object graphs")
  46. # EOF