【问题标题】:Recursion limit exceeded with cython cdef classes and supercython cdef 类和 super 超出了递归限制
【发布时间】:2021-06-10 14:25:08
【问题描述】:

我在 Cython 2.0 下运行这段代码时遇到了一些问题:

cdef class Foo(object):
  cpdef twerk(self): #using def instead does not help
    print "Bustin' some awkward moves."

cdef class ShyFoo(Foo):
  cpdef twerk(self):
    print "Do I really have to?"
    super(self, ShyFoo).twerk()
    print "I hate you so much."

ShyFoo().twerk()

RuntimeError: 调用 Python 对象时超出最大递归深度

但是,删除 cdefs 并将 cpdefs 替换为 defs 可以让我使用 Python。

回溯是这样的:

File "mytest.pyx", line 61, in mytest.Foo.twerk
  cpdef twerk(self):
File "mytest.pyx", line 67, in mytest.ShyFoo.twerk
  super(ShyFoo, self).twerk()
File "mytest.pyx", line 61, in mytest.Foo.twerk
  cpdef twerk(self):
File "mytest.pyx", line 67, in mytest.ShyFoo.twerk
    super(ShyFoo, self).twerk()
....................................................

我做错了什么?我从 4 年前找到了this relevant ticket,但我猜它因为用户错误而没有引起注意。

【问题讨论】:

    标签: cython


    【解决方案1】:

    您在问题中链接到的错误似乎是问题所在。如果将这两种方法都更改为 def 而不是 cpdef,则可以正常工作。或者,您可以像这样删除对 super 的调用:

    cdef class Foo(object):
        cpdef twerk(self):
            print "Bustin' some awkward moves."
    
    cdef class ShyFoo(Foo):
        cpdef twerk(self):
            print "Do I really have to?"
            Foo.twerk(self)
            print "I hate you so much."
    
    ShyFoo().twerk()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2015-05-20
      • 2019-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多