码迷,mamicode.com
首页 > 编程语言 > 详细

Python 显示调用栈

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

标签:style   blog   color   os   io   for   ar   div   

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 显示调用栈

标签:style   blog   color   os   io   for   ar   div   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!