Pyjnius:从实例访问静态变量时Python崩溃

时间:2018-03-12 17:51:31

标签: static crash pyjnius

我已经开始使用Pyjnius而且我遇到了一个严重的错误。 我没有找到任何参考,但获得它是如此简单,我严重怀疑我是第一个体验它。

基本上,如果我尝试访问一个通过实例的类的静态成员,我会得到整个Python解释器的崩溃,除非我之前已经通过类为成员分配了值。

我的JAVA课就是这样:

class TestClass {
    public static int b;
    public double c;

    public TestClass(int cc)  {
        c = cc;
    }
}

我的测试Python脚本很简单:

from jnius import autoclass

the_class = autoclass('TestClass')

the_object = the_class(42.0)    # create an instance
print(the_object.c)             # no problem accessing the non-static member

the_object.c = 12.56
print(the_object.c)             # no problem modifying the non-static member

print(the_class.b)              # no problem accessing the static member from the class

#print(the_object.b)            # crash if I access the static member from the instance!!!!

the_class.b = 42
print(the_class.b)              # no problem modifying the static member from the class

print(the_object.b)             # and now I can also access it from the instance, but only after I have modified it

现在,如果我取消注释访问the_object.b的行,那么在我从类中修改它的值之前,我会完全崩溃Python解释器。

如果我访问类的任何数字或字符串成员,而不是静态方法,则会发生同样的崩溃:我可以毫无问题地从实例访问它们。

我正在运行:

  • Windows 10

  • Python 3.6.2

  • Pyjnius 1.1.1

  • Java 1.8.0_161

有没有人有相同的行为,或者你能建议任何解决方案吗?

0 个答案:

没有答案