python使用gc.get_objects()查看运行时对象,,从python2.2开始
python使用gc.get_objects()查看运行时对象,,从python2.2开始
从python2.2开始允许开发人员可以通过get_objects()方法获得被垃圾回收器控制的对象列表。 通过这种方式可以获得运行时程序中都有什么对象。
import gcimport inspectexclude = [ "function", "type", "list", "dict", "tuple", "wrapper_descriptor", "module", "method_descriptor", "member_descriptor", "instancemethod", "builtin_function_or_method", "frame", "classmethod", "classmethod_descriptor", "_Environ", "MemoryError", "_Printer", "_Helper", "getset_descriptor", ]def dumpObjects(): gc.collect() oo = gc.get_objects() for o in oo: if getattr(o, "__class__", None): name = o.__class__.__name__ if name not in exclude: filename = inspect.getabsfile(o.__class__) print "Object of class:", name, "...", print "defined in file:", filename if __name__=="__main__": class TestClass: pass testObject1 = TestClass() testObject2 = TestClass() dumpObjects()
相关内容
- Python计算单词距离代码,python计算单词,#!/usr/bin/e
- Python处理gzip压缩过的网页,python处理gzip压缩,大多数网
- Python判断一个数字是否为素数,python素数,如下代码判断
- python urllib2使用ProxyHandler通过代理访问网页,,在urllib
- python webpy 输出json响应,webpyjson,webpy输出json首
- webpy获得用户post或者get的数据,上传文件示例,webpyp
- python getaddrinfo() 基本使用代码,pythongetaddrinfo,import sy
- Execute a function on multiple argument sets in parallel using a thre
- python urllib.urlopen获得response后检查http响应头中的conten
- python转换字符串为datetime类型,pythondatetime,>>>
评论关闭