首页 > 编程语言 > 详细

Python 显示调用栈

时间:2014-08-20 01:16:05      阅读:669      评论:0      收藏:0      [点我收藏+]

Python调试不如强类型的语言方便,显示调用栈有时非常必要,inspect模块很好用

import inspect

inspect.stack()

inspect.stack()返回的是一个函数栈帧列表如(已经做了一个for e in inspect(): print e 转化)

(<frame object at 0x7f6ec27b2050>, ‘/usr/lib/python2.7/dist-packages/oslo/config/cfg.py‘, 495, ‘_is_opt_registered‘, [‘    st = inspect.stack()\n‘], 0)
(<frame object at 0x7f6ec2807d00>, ‘/usr/lib/python2.7/dist-packages/oslo/config/cfg.py‘, 1163, ‘_register_opt‘, [‘        if _is_opt_registered(self._opts, opt):\n‘], 0)
(<frame object at 0x7f6ec280bb90>, ‘/usr/lib/python2.7/dist-packages/oslo/config/cfg.py‘, 1710, ‘register_opt‘, [‘            return group._register_opt(opt, cli)\n‘], 0)
(<frame object at 0x1a4f180>, ‘/usr/lib/python2.7/dist-packages/oslo/config/cfg.py‘, 1591, ‘__inner‘, [‘                return f(self, *args, **kwargs)\n‘], 0)
(<frame object at 0x1a805f0>, ‘/usr/lib/python2.7/dist-packages/oslo/config/cfg.py‘, 1723, ‘register_opts‘, [‘            self.register_opt(opt, group, clear_cache=False)\n‘], 0)
(<frame object at 0x1a941f0>, ‘/usr/lib/python2.7/dist-packages/oslo/config/cfg.py‘, 1587, ‘__inner‘, [‘                result = f(self, *args, **kwargs)\n‘], 0)
(<frame object at 0x1ac0bb0>, ‘/usr/lib/python2.7/dist-packages/nova/openstack/common/db/options.py‘, 131, ‘<module>‘, ["CONF.register_opts(database_opts, ‘database‘)\n"], 0)
(<frame object at 0x7f6ec2870aa0>, ‘/usr/lib/python2.7/dist-packages/nova/config.py‘, 21, ‘<module>‘, [‘from nova.openstack.common.db import options\n‘], 0)
(<frame object at 0x7f6ec381c050>, ‘/usr/lib/python2.7/dist-packages/nova/cmd/api.py‘, 27, ‘<module>‘, [‘from nova import config\n‘], 0)
(<frame object at 0x7f6ec4f4cc20>, ‘/usr/bin/nova-api‘, 6, ‘<module>‘, [‘from nova.cmd.api import main\n‘], 0)

 

Python 显示调用栈,布布扣,bubuko.com

Python 显示调用栈

原文:http://www.cnblogs.com/lailailai/p/3923568.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!