Kivy:错误弱引用对象(在时钟函数中)不再存在

Kivy : Error weakly-referenced object (in a clock function) no longer exists(Kivy:错误弱引用对象(在时钟函数中)不再存在)
本文介绍了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)

此信息在 kivy 时钟文档 :

重要

回调是弱引用的:你负责保持一个引用您的原始对象/回调.如果你不保留一个参考,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

感谢阅读!

推荐答案

官方文档(Kv 语言编程指南) 说要在 KV 代码中添加诸如 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.

所做 的工作是通过将其添加到 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 中修复.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)