gpt4 book ai didi

python - 一个 Numpy 错误,看似与抛出它的脚本无关,但不会显示在调试器上

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:48 25 4
gpt4 key购买 nike

所以我有 foo,一个由普通 float 组成的普通元组。在我的脚本中调用 map 会莫名其妙地抛出所有事情的 Numpy 错误,即使代码没有任何问题。进入调试器并执行完全相同的代码不会产生预期的错误。有谁知道会发生什么?我完全不知所措。这怎么可能?

此外,对于那些要求使用最小脚本来重现问题的人:我无法使用简短的片段来重现它,而且我无法发布整个脚本,因为它是用于家庭作业的。

Traceback (most recent call last):
File "py_code\ps4-code.py", line 240, in <module>
doPairMatch(transA, transB, tapoints, tbpoints, 1, ransacTranslate)
File "py_code\ps4-code.py", line 217, in doPairMatch
print map(int, foo)
TypeError: expected a single-segment buffer object
>>> import pdb;pdb.pm()
> c:\homework\cs4495\ps4\py_code\ps4-code.py(217)doPairMatch()
-> print map(int, foo)
(Pdb) print foo
(603.0, 437.0)
(Pdb) print map(int, foo)
[603, 437]
(Pdb) print type(foo)
<type 'tuple'>
(Pdb) print int, map, type
<type 'int'> <built-in function map> <type 'type'>
(Pdb) map(type, foo)
[<type 'float'>, <type 'float'>]
(Pdb)

编辑:好吧,至少我知道这是怎么可能的。问题似乎是在垃圾回收期间发生的,这就是为什么错误随机出现在不相关的代码部分的原因。据推测,gc 在 OpenCV 的某处触发了一个错误,导致一切崩溃。

Exception TypeError: 'expected a single-segment buffer object' in 'garbage colle
ction' ignored
Fatal Python error: unexpected exception during garbage collection

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

最佳答案

我知道这种异常有不同的原因:有问题的 C 扩展模块(OpenCV?)。如果在从该模块执行某些 C 函数期间引发 TypeError,但该模块缺少检测它的代码,那么它可以在 C 函数执行后保持未检测到。稍后它会突然出现。

我无法知道我是否正确,但一个很好的指标是在“map(int, foo)”之前的几行是否调用了这样的 C 扩展模块。一种确定的方法是在此“map(int, foo)”之前放置另一行,以检测遗留异常。事实证明,它可以是例如“all([])”。如果你在 "all([])"行得到 TypeError,那么很明显这是一个遗留异常。

关于python - 一个 Numpy 错误,看似与抛出它的脚本无关,但不会显示在调试器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13204843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com