本文整理匯總了Python中pdb.set_trace方法的典型用法代碼示例。如果您正苦於以下問題:Python pdb.set_trace方法的具體用法?Python pdb.set_trace怎麽用?Python pdb.set_trace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pdb
的用法示例。
在下文中一共展示了pdb.set_trace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_trace
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def set_trace():
"""Call pdb.set_trace in the caller's frame.
First restore sys.stdout and sys.stderr. Note that the streams are
NOT reset to whatever they were before the call once pdb is done!
"""
import pdb
for stream in 'stdout', 'stderr':
output = getattr(sys, stream)
orig_output = getattr(sys, '__%s__' % stream)
if output != orig_output:
# Flush the output before entering pdb
if hasattr(output, 'getvalue'):
orig_output.write(output.getvalue())
orig_output.flush()
setattr(sys, stream, orig_output)
exc, tb = sys.exc_info()[1:]
if tb:
if isinstance(exc, AssertionError) and exc.args:
# The traceback is not printed yet
print_exc()
pdb.post_mortem(tb)
else:
pdb.Pdb().set_trace(sys._getframe().f_back)
示例2: get_angle_diff
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def get_angle_diff(self, target, result):
size = target.size()
sequence_length = size[1]
all_averages = np.zeros((sequence_length)).astype(np.float)
for seq_id in range(sequence_length):
average = AverageMeter()
for batch_id in range(size[0]):
for imu_id in range(size[2]):
goal = Quaternion(target[batch_id, seq_id, imu_id])
out = Quaternion(result[batch_id, seq_id, imu_id])
acos = (2 * (np.dot(out.normalised.q, goal.normalised.q)**2)
- 1)
acos = round(acos, 6)
if acos > 1 or acos < -1:
pdb.set_trace()
radian = math.acos(acos)
average.update(radian)
all_averages[seq_id] = (average.avg)
return all_averages
示例3: choose_dimension
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def choose_dimension(partition):
"""
choose dim with largest norm_width from all attributes.
This function can be upgraded with other distance function.
"""
max_width = -1
max_dim = -1
for dim in range(QI_LEN):
if partition.allow[dim] == 0:
continue
norm_width = get_normalized_width(partition, dim)
if norm_width > max_width:
max_width = norm_width
max_dim = dim
if max_width > 1:
pdb.set_trace()
return max_dim
示例4: rebalance_portfolio
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def rebalance_portfolio(context, data, weights):
desired_amount = np.zeros(np.shape(weights))
current_amount = np.zeros(np.shape(weights))
prices = np.zeros(np.shape(weights))
if context.init:
positions_value = context.portfolio.starting_cash
else:
#total cash
positions_value = context.portfolio.positions_value + context.portfolio.cash
for i, stock in enumerate(context.stocks):
current_amount[i] = context.portfolio.positions[stock].amount #shares
prices[i] = data[stock]['price'] #share price
context.prev_weights = weights
desired_amount = np.round(weights * positions_value / prices) #shares
diff_amount = desired_amount - current_amount
#pdb.set_trace()
for i, sid in enumerate(context.sids):
order(sid, +diff_amount[i])
示例5: obb_hybrid_NMS
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def obb_hybrid_NMS(thresh_obb, dets, thresh_hbb=0.5):
"""
do nms on obbs by 1. corresponding hbbs on relative high thresh 2. then nms by obbs on obbs
:param dets:
:param thresh:
:return:
"""
# pdb.set_trace()
h_dets = bbox_poly2hbb(dets)
h_keep = py_cpu_nms(h_dets, thresh_hbb)
h_keep = np.array(h_keep)
keeped_o_dets = dets[h_keep, :]
o_keep = py_cpu_nms_poly_fast(keeped_o_dets, thresh_obb)
final_keep = h_keep[o_keep]
return final_keep
示例6: bbox_poly2hbb
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def bbox_poly2hbb(boxes):
"""
with label
:param boxes: (x1, y1, ... x4, y4, score) [n, 9]
:return: hbb: (xmin, ymin, xmax, ymax, score) [n, 5]
"""
n = boxes.shape[0]
hbbs = np.zeros((n, 4))
xs = np.reshape(boxes[:, : -1], (n, 4, 2))[:, :, 0]
ys = np.reshape(boxes[:, : -1], (n, 4, 2))[:, :, 1]
# pdb.set_trace()
hbbs[:, 0] = np.min(xs, axis=1)
hbbs[:, 1] = np.min(ys, axis=1)
hbbs[:, 2] = np.max(xs, axis=1)
hbbs[:, 3] = np.max(ys, axis=1)
hbbs = np.hstack((hbbs, boxes[:, -1, np.newaxis]))
return hbbs
示例7: best_match_dbbox2delta
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def best_match_dbbox2delta(Rrois, gt, means = [0, 0, 0, 0, 0], stds=[1, 1, 1, 1, 1]):
"""
:param Rrois: (x_ctr, y_ctr, w, h, angle)
shape (n, 5)
:param gt: (x_ctr, y_ctr, w, h, angle)
:param means:
:param stds:
:return: encoded targets: shape (n, 5)
"""
# TODO: for comparision, dot not change the regression range for angle in 2 stage currently
# This is a simplified version
# TODO: preprocess angle of gt_boxes according to the catogeries
# Here, use a choose beste match angle, similar to choose best point instead
gt_boxes_new = choose_best_match_batch(Rrois, gt)
try:
assert np.all(Rrois.cpu().numpy()[:, 4] <= (np.pi + 0.001))
except:
import pdb
pdb.set_trace()
bbox_targets = dbbox2delta_v2(Rrois, gt_boxes_new, means, stds)
return bbox_targets
# TODO: check the negative situation of flip
示例8: get_best_begin_point
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def get_best_begin_point(coordinate_list):
best_coordinate_list = map(get_best_begin_point_warp_single, coordinate_list)
# import pdb
# pdb.set_trace()
best_coordinate_list = np.stack(list(best_coordinate_list))
return best_coordinate_list
# def polygonToRotRectangle(polys):
# """
# pytorch version, batch operation
# :param polys: The polygon stored in format [x1, y1, x2, y2, x3, y3, x4, y4]
# shape [num_boxes, 8]
# :return: Rotated Rectangle in format [cx, cy, w, h, theta]
# shape [num_rot_recs, 5]
# """
# polys = polys.view(-1, 4, 2)
示例9: xy2wh_c
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def xy2wh_c(boxes):
"""
:param boxes: (xmin, ymin, xmax, ymax) (n, 4 * #C)
:return: out_boxes: (x_ctr, y_ctr, w, h) (n, 4 * #C)
"""
num_boxes = boxes.size(0)
out_boxes = boxes.clone()
ex_widths = boxes[..., 2::4] - boxes[..., 0::4] + 1.0
ex_heights = boxes[..., 3::4] - boxes[..., 1::4] + 1.0
ex_ctr_x = boxes[..., 0::4] + 0.5 * (ex_widths - 1.0)
ex_ctr_y = boxes[..., 1::4] + 0.5 * (ex_heights - 1.0)
# import pdb; pdb.set_trace()
out_boxes[..., 2::4] = ex_widths
out_boxes[..., 3::4] = ex_heights
out_boxes[..., 0::4] = ex_ctr_x
out_boxes[..., 1::4] = ex_ctr_y
return out_boxes
示例10: setBreak
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def setBreak(self,breakFlag = True):
"""Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
"""
if breakFlag:
_parseMethod = self._parse
def breaker(instring, loc, doActions=True, callPreParse=True):
import pdb
pdb.set_trace()
return _parseMethod( instring, loc, doActions, callPreParse )
breaker._originalParseMethod = _parseMethod
self._parse = breaker
else:
if hasattr(self._parse,"_originalParseMethod"):
self._parse = self._parse._originalParseMethod
return self
示例11: exec_expr
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def exec_expr(self, s):
out = StringIO()
exec_lock.acquire()
save_stdout = sys.stdout
try:
debugger = _OutputRedirectingPdb(save_stdout)
debugger.reset()
pdb.set_trace = debugger.set_trace
sys.stdout = out
try:
code = compile(s, '<web>', "single", 0, 1)
exec code in self.namespace, self.globs
debugger.set_continue()
except KeyboardInterrupt:
raise
except:
traceback.print_exc(file=out)
debugger.set_continue()
finally:
sys.stdout = save_stdout
exec_lock.release()
return out.getvalue()
# From doctest
示例12: visit_if
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def visit_if(self, if_):
# Select which of the conditional_blocks are valid. Choose the first one
# which evaluates to non zero.
for block in if_.conditional_blocks:
# First expand all the macros in the condition.
conditional_expression = self._macro_expander.expand(
block.conditional_expression, eval_mode=True)
expression = self._expression_parser.parse(conditional_expression)
try:
# Choose the block if the evaluator returns truth.
if self._expression_evaluator.evaluate(expression):
return block.accept(self)
except c_ast.IrreducibleFunction as e:
print("Unable to evaluate conditional_expression: %s"
% block.conditional_expression)
print("Expanded to: %s"
% conditional_expression)
print("Error: %s" % e)
import pdb
pdb.set_trace()
示例13: start_x
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def start_x(a, b):
from pdb import Pdb
import os
from pty import openpty
(master, slave) = openpty()
cmd = "rxvt -pty-fd {} &".format(master)
os.system(cmd)
io = os.fdopen(slave, "r+b")
Pdb(stdin=io, stdout=io).set_trace()
# set a handler on SIGUSR1. NB although all the above shoudln't really
# work as signal handlers, because they call system calls which you are
# not supposed to use in a handler, these are okay because in fact
# python is handling the signal in C then interpreting these 'handlers'
# outside the handler.
# To use: pydebug.patch_handler(pydebug.start_x)
示例14: waccuracy
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def waccuracy(output, batch, *args, **kwargs):
indices, (sentence, ), (label, ) = batch
output, attn = output
index = label
src = Var(torch.ones(label.size()))
acc_nomin = Var(torch.zeros(output.size(1)))
acc_denom = Var(torch.ones(output.size(1)))
acc_denom.scatter_add_(0, index, (label == label).float() )
acc_nomin.scatter_add_(0, index, (label == output.max(1)[1]).float())
accuracy = acc_nomin / acc_denom
#pdb.set_trace()
return accuracy.mean()
示例15: parse_1
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import set_trace [as 別名]
def parse_1(self, response):
info('Parse '+response.url)
#sel = Selector(response)
#v = sel.css('.gs_ggs a::attr(href)').extract()
#import pdb; pdb.set_trace()
x = self.parse_with_rules(response, self.list_css_rules, dict)
items = []
if len(x) > 0:
items = x[0]['.gs_r']
pp.pprint(items)
import pdb; pdb.set_trace()
# return self.parse_with_rules(response, self.css_rules, googlescholarItem)
for item in items:
if item['related-url'] == '' or item['related-type'] != '[PDF]':
continue
url = item['related-url']
info('pdf-url: ' + url)
yield Request(url, callback=self.save_pdf)