问题
So here is my error code I think there's something hard in this error, i looked on forums but couldn't find out.
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
What i tried :
- make "strong references" so the gc dont delete it with:
id: id.__self__
in my kv file
- make "strong references" with :
self.refs = [
self.id.__self__,
self.id.__self__]
-Use the ErrorHandler to handle the error but the error keep coming for ever
What I think cause the error but I have no idea how to fix it:
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)
this information in the kivy clock documentation :
Important
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 :
[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
Thanks for reading !
回答1:
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.
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
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.
Credit for this goes to the beautiful answer from leo10011.
Update 2020-05-19: This bug reportedly has been fixed in Kivy 2.0.
回答2:
What I usually do to keep a reference to e.g. my_object
is to add my_object: my_object.__self__
line in the kv
part of my root
rule.
Since you haven't provide any code, I can't be more specific...
来源:https://stackoverflow.com/questions/61658224/kivy-error-weakly-referenced-object-in-a-clock-function-no-longer-exists