Kivy:错误的弱引用对象(在时钟函数中)不再存在 [英] Kivy : Error weakly-referenced object (in a clock function) no longer exists

查看:110
本文介绍了Kivy:错误的弱引用对象(在时钟函数中)不再存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的错误代码 我认为此错误有些棘手,我在论坛上看了一下,但找不到.

So here is my error code I think there's something hard in this error, i looked on forums but couldn't find out.

然后...我的手机上出现错误 (使用 kivy启动器python 3 以及当我使用buildozer进行构建时)但不在我的计算机上(ubuntu 18.0.4和Windows 10) 从我的理解来看,该错误来自垃圾收集器,该垃圾收集器删除了引用,并且代码尝试在垃圾收集器之后访问该引用.但是我不确定我是否会理解垃圾收集器的事情

And ... i have the error on my phone (with kivy launcher python 3 and when i build with buildozer) but not on my computer (ubuntu 18.0.4 and windows 10) The error, from what i understand, comes from the garbage collector that delete a reference and the code try to access the reference after the garbage collector. but i am not sure if I rly understand the garbage collector thing

我尝试过的事情:

  • 创建强引用",以便gc不会使用以下命令将其删除:
    id: id.__self__

在我的kv文件中

  • 使用:
  • 进行强引用"
     self.refs = [
                self.id.__self__,
                self.id.__self__]

-使用ErrorHandler处理错误,但错误永远存在

-Use the ErrorHandler to handle the error but the error keep coming for ever

我认为是导致错误的原因,但我不知道如何解决该问题:

  • 我用来向服务器发送请求的时钟,但是我不知道为什么(self.requestClient是发送请求的函数):

  • the clock I use to send request to the server but i don't know why (self.requestClient is a function to send a request) :

C = Clock.schedule_interval(self.requestClient,5)

C = Clock.schedule_interval(self.requestClient, 5)

重要

回调是弱引用的:您负责保持 引用原始对象/回调.如果您不保留 参考,ClockBase将永远不会执行您的回调

The callback is weak-referenced: you are responsible for keeping a reference to your original object/callback. If you don’t keep a reference, the ClockBase will never execute your callback

错误:

[ERROR  ] Exception catched by ExceptionHandler
05-07 11:27:45.694  2788  2823 I python  : Traceback (most recent call last):
05-07 11:27:45.694  2788  2823 I python  :   File path/kivy-launcher/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/launcher/kivy/core/window/window_sdl2.py", line 747, in mainloop
05-07 11:27:45.694  2788  2823 I python  :   File "/path/kivy-launcher/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/launcher/kivy/core/window/window_sdl2.py", line 479, in _mainloop
05-07 11:27:45.694  2788  2823 I python  :   File "/path/kivy-launcher/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/launcher/kivy/base.py", line 339, in idle
05-07 11:27:45.694  2788  2823 I python  :   File "/path/kivy-launcher/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/launcher/kivy/clock.py", line 591, in tick
05-07 11:27:45.694  2788  2823 I python  :   File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
05-07 11:27:45.694  2788  2823 I python  :   File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
05-07 11:27:45.694  2788  2823 I python  :   File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
05-07 11:27:45.694  2788  2823 I python  :   File "kivy/_clock.pyx", line 154, in kivy._clock.ClockEvent.tick
05-07 11:27:45.694  2788  2823 I python  :   File "kivy/_clock.pyx", line 86, in kivy._clock.ClockEvent.get_callback
05-07 11:27:45.694  2788  2823 I python  :   File "/path/kivy-launcher/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/launcher/kivy/weakmethod.py", line 56, in is_dead
05-07 11:27:45.694  2788  2823 I python  : ReferenceError: weakly-referenced object no longer exists

感谢您的阅读!

推荐答案

官方文档(id_name: id_name.__self__,但是尚不清楚在哪里需要这样做.而且,它没有为我解决ReferenceError: weakly-referenced object no longer exists错误.

The official documentation (Kv language Programming Guide) says to add 'strong' references such as id_name: id_name.__self__ in the KV code, but it is unclear where this is necessary. What's more, it did not solve the ReferenceError: weakly-referenced object no longer exists errors for me.

did 的工作是通过将Buildozer添加到buildozer.spec文件的requirements行来强制Buildozer使用hostpython3的特定版本:

What did work is forcing Buildozer to use a specific version of hostpython3 by adding this to the requirements line of the buildozer.spec file:

python3==3.7.5, hostpython3==3.7.5

另一个注意事项:将以上内容添加到requirements后,我回过头去并删除了所有__self__参考,它仍然可以正常工作,因此显然在Kivy KV语言中不再需要这些.

One more note: after adding the above to requirements, I went back and removed all my __self__ references and it still worked fine, so apparently these are no longer needed in Kivy KV language.

对此的信用转到来自leo10011的漂亮答案.

更新2020-05-19 :此错误据报道已在Kivy 2.0中修复.

Update 2020-05-19: This bug reportedly has been fixed in Kivy 2.0.

这篇关于Kivy:错误的弱引用对象(在时钟函数中)不再存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆