我想我找到了问题所在。多线程应用程序中的inspect模块和底层C代码似乎有问题。上面代码的模块正在从不同的线程导入。第二张图指出了问题所在。
function
下面第三个节点中列出的是inspect.getmodule()。我不能把所有的东西都放在里面,所以不得不修剪。
(Pdb) objgraph.at(3510928)
<cell at 0x359290: dict object at 0x3849c0>
听写里面是所有的画面
(Pdb) objgraph.at(0x3849c0)
{(<frame object at 0x97a288>, '/lib/python26.zip/logging/__init__.py'): <module 'logging' from '/lib/python26.zip/logging/__init__.py'>,
(<frame object at 0x896288>, '/lib/python26.zip/logging/__init__.py'): <module 'logging' from '/lib/python26.zip/logging/__init__.py'>,
(<frame object at 0xa621b0>, '/lib/python26.zip/logging/__init__.py'): <module 'logging' from '/lib/python26.zip/logging/__init__.py'>,
(<frame object at 0x11266e8>, '/lib/python26.zip/logging/__init__.py'): <module 'logging' from '/lib/python26.zip/logging/__init__.py'>,
...}
如果你得到所有这些框架的外部框架
(Pdb) inspect.getouterframes(objgraph.at(0x97a288))
[(<frame object at 0x97a288>, '/lib/python26.zip/logging/__init__.py', 1028, 'debug', [' self._log(DEBUG, msg, args, **kwargs)\n'], 0),
(<frame object at 0x794040>, '/lib/python26.zip/logging/__init__.py', 1505, 'debug', [' root.debug(*((msg,)+args), **kwargs)\n'], 0),
(<frame object at 0x794e58>, '/mmc/src/core/controller/main.py', 1046, '__startCharge', [' self.chargeLock.release()\n'], 0),
(<frame object at 0x5c4260>, '/mmc/src/core/controller/main.py', 1420, 'watchScheduleStartChargeCondition', [' ret = self.__startCharge(0, eventCode=eventCode)\n'], 0),
(<frame object at 0x5c0dd0>, '/home/ephibian/Python2/_install/lib/python2.6/threading.py', 484, 'run', None, None),
(<frame object at 0x5c3b48>, '/home/ephibian/Python2/_install/lib/python2.6/threading.py', 532, '__bootstrap_inner', None, None),
(<frame object at 0x218170>, '/home/ephibian/Python2/_install/lib/python2.6/threading.py', 504, '__bootstrap', None, None)]
它们都指向线程中的引导方法。我可能走错了方向,但其中一些框架的上下文离调用我发布的方法还很远。