python计算排队时间_Python(pdb) - 排队执行命令

I am implementing a "breakpoint" system for use in my Python development that will allow me to call a function that, in essence, calls pdb.set_trace();

Some of the functionality that I would like to implement requires me to control pdb from code while I am within a set_trace context.

Example:

disableList = []

def breakpoint(name=None):

def d():

disableList.append(name)

#****

#issue 'run' command to pdb so user

#does not have to type 'c'

#****

if name in disableList:

return

print "Use d() to disable breakpoint, 'c' to continue"

pdb.set_trace();

In the above example, how do I implement the comments demarked by the #**** ?

In other parts of this system, I would like to issue an 'up' command, or two sequential 'up' commands without leaving the pdb session (so the user ends up at a pdb prompt but up two levels on the call stack).

解决方案

You could invoke lower-level methods to get more control over the debugger:

def debug():

import pdb

import sys

# set up the debugger

debugger = pdb.Pdb()

debugger.reset()

# your custom stuff here

debugger.do_where(None) # run the "where" command

# invoke the interactive debugging prompt

users_frame = sys._getframe().f_back # frame where the user invoked `debug()`

debugger.interaction(users_frame, None)

if __name__ == '__main__':

print 1

debug()

print 2

You can find documentation for the pdb module here: http://docs.python.org/library/pdb and for the bdb lower-level debugging interface here: http://docs.python.org/library/bdb. You may also want to look at their source code.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值