ReferenceError: weakly-referenced object no longer exists

458 views
Skip to first unread message

Dilshad khan

unread,
Apr 23, 2020, 11:11:04 AM4/23/20
to Kivy users support
I am new to kivy. I wrote an app in kivy which makes a call to an API. I am getting following error in my APK file just after calling API. 

Any help what could be wrong in my code.

04-23 16:50:31.540 19053 19087 I python  :    File "/home/eurdu/khidmat/sevak/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/sevak/kivy/clock.py", line 591, in tick

04-23 16:50:31.541 19053 19087 I python  :    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events

04-23 16:50:31.542 19053 19087 I python  :    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events

04-23 16:50:31.543 19053 19087 I python  :    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events

04-23 16:50:31.544 19053 19087 I python  :    File "kivy/_clock.pyx", line 154, in kivy._clock.ClockEvent.tick

04-23 16:50:31.545 19053 19087 I python  :    File "kivy/_clock.pyx", line 86, in kivy._clock.ClockEvent.get_callback

04-23 16:50:31.546 19053 19087 I python  :    File "/home/eurdu/khidmat/sevak/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/sevak/kivy/weakmethod.py", line 56, in is_dead

04-23 16:50:31.547 19053 19087 I python  :  ReferenceError: weakly-referenced object no longer exists

04-23 16:50:31.547 19053 19087 I python  : Python for android ended.

Robert Flatt

unread,
Apr 23, 2020, 1:13:42 PM4/23/20
to Kivy users support

It sounds like "an API" contains a weakref that something (the app code or inside the API?) depends on, but there was some period where there were no strong references to the weakref. So the garbage collector is entitled to remove it, but may or may not have done so. To re-reference the object is a programming error.

In this case the behavior is non-deterministic. (See https://docs.python.org/3/library/weakref.html "However, until the object is actually destroyed the weak reference may return the object even if there are no strong references to it.")

One would expect that a platform port might expose an issue of this type. Do you see not see this issue on another platform?

Dilshad khan

unread,
Apr 23, 2020, 1:55:27 PM4/23/20
to kivy-...@googlegroups.com
Dear Robert,
Thanks for your reply. This is the strange part, I don't get this error in python or windows. This error comes only in android.  I read that UrlRequest is asynchronus to make it syncronus we need to call wait method "If you want a synchronous request, you can call the wait() method."  https://kivy.org/doc/stable/api-kivy.network.urlrequest.html. However this also dont seems to work.

Regards


--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/D6xSMI3jp-c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/820e0b2a-e828-4478-b1c0-9e7dea157a02%40googlegroups.com.

Robert Flatt

unread,
Apr 23, 2020, 3:52:17 PM4/23/20
to Kivy users support
Thanks for your reply. This is the strange part, I don't get this error in python or windows.
Not strange at all, the detailed behavior of garbage collection should be expected to be different between OS, see also my previous post.
The issue is either in the API docs, the API code, or the use of the API in the app.

Separate issue, I assume:
I read that UrlRequest is asynchronus to make it syncronus
You can do this, but you usually shouldn't.
Search here for several posts on this. I don't really know what the issue is because I never looked at it.
But best advice don't do that!
A synchronous UrlRequst on Android's UI thread is almost certainly not allowed by Android (look in the logcat).
I suppose you could do it in a Thread, but then you still have to deal with synchronizing so there seems little point.

Android is not a POSIX operating system, expect OS related operations to be sometimes different.
To unsubscribe from this group and all its topics, send an email to kivy-...@googlegroups.com.

Robert Flatt

unread,
Apr 24, 2020, 4:56:56 PM4/24/20
to Kivy users support
The detailed behavior of garbage collection changed in Python 3.8 and exposed a Kivy issue that can occur.
This is fixed in Kivy, but not the release 1.11.1 version. 
A previous version of p4a uses Python 3.7.  So in .spec set

p4a.branch = 2019.10.6

and clean the build

Dilshad khan

unread,
Apr 26, 2020, 1:08:44 AM4/26/20
to kivy-...@googlegroups.com
Dear Robert,
Thank you very much. I did as per your suggestion. But my bad luck I got this error.

warning: Could not find remote branch 2019.10.6 to clone.
fatal: Remote branch 2019.10.6 not found in upstream origin

Regards
Dilshad

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e3a411e3-8c28-4e2d-a5c0-8a2439e08bfa%40googlegroups.com.

Robert Flatt

unread,
Apr 26, 2020, 2:04:03 AM4/26/20
to Kivy users support
Don't know why that would be, it worked for me.

You can see what versions are available by typing an empty version request:

pip3 install python-for-android==

Which returns, as expected, an error; and the available versions (right now I get):

ERROR: Could not find a version that satisfies the requirement python-for-android== (from versions: 0.4, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.6.0, 0.7.0, 2019.6.6, 2019.6.6.post0, 2019.7.8, 2019.8.9, 2019.10.6, 2020.3.30)
ERROR: No matching distribution found for python-for-android==

And in there is 2019.10.6  

Dilshad khan

unread,
Apr 26, 2020, 2:40:28 AM4/26/20
to kivy-...@googlegroups.com
Yes, I got same output on running the command
pip3 install python-for-android== 

however on putting it through git

git clone -b 2019.10.6 --single-branch https://github.com/kivy/python-for-android.git python-for-android

I got this error

Cloning into 'python-for-android'...

warning: Could not find remote branch 2019.10.6 to clone.
fatal: Remote branch 2019.10.6 not found in upstream origin
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c6e8eedd-eac1-4ae0-a32d-a2673481b65d%40googlegroups.com.

Robert Flatt

unread,
Apr 26, 2020, 2:51:45 AM4/26/20
to Kivy users support
Look at the branch names on github:     release-..
Perhaps that will do it.

Are you doing this standalone? Or did you look to see what Buildozer is doing?

Dilshad khan

unread,
Apr 26, 2020, 4:11:28 AM4/26/20
to kivy-...@googlegroups.com
I did both


To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6f1bb9ed-643f-4f08-8acc-25e8380d03dd%40googlegroups.com.

Dilshad khan

unread,
Apr 26, 2020, 4:16:50 AM4/26/20
to kivy-...@googlegroups.com
It is "release-2019.10.06"

no error :)

Let me build and see

Thanks once again

Dilshad khan

unread,
Apr 26, 2020, 4:30:58 AM4/26/20
to kivy-...@googlegroups.com
my bad 
again there is error while building using buildozer.

In file included from /home/eurdu/khidmat/sevak/.buildozer/android/platform/build-armeabi-v7a/build/bootstrap_builds/sdl2-python3/jni/application/src/start.c:3:
/home/eurdu/khidmat/sevak/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Include/Python.h:8:10: fatal error:
      'pyconfig.h' file not found
#include "pyconfig.h"
         ^~~~~~~~~~~~

Robert Flatt

unread,
Apr 26, 2020, 12:43:45 PM4/26/20
to Kivy users support
Did you clean first?
I did both


Dilshad khan

unread,
Apr 27, 2020, 2:58:40 AM4/27/20
to kivy-...@googlegroups.com
Yes 

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d69dbe11-5b63-4fd5-8928-afae39679dd9%40googlegroups.com.

Robert Flatt

unread,
Apr 27, 2020, 1:20:43 PM4/27/20
to Kivy users support
No idea what the cause of this issue is.
I think perhaps I used p4a directly when looking at this issue, but I don't know if this would help you because I don't know the cause of your issue.

Another thing to try would be to go back to the default p4a in Buildozer (and clean) and set requirements kivy==2.0.0rc1
This will give you a Kivy that addresses the issue you have (but it is a release candidate, so there may be issues)
Also it may expose a similar outstanding issue  https://github.com/HeaTTheatR/KivyMD/issues/268

It would be helpful to know if your "an APK" is KivyMD?
Yes 

Robert Flatt

unread,
Apr 28, 2020, 1:05:00 PM4/28/20
to Kivy users support
Looks like KivyMD fixed the issue  https://github.com/HeaTTheatR/KivyMD/issues/248

Wilson Mutebi

unread,
Apr 28, 2020, 2:13:52 PM4/28/20
to kivy-...@googlegroups.com
Looks we are having yhe same issue. But is there a way of building the apk with python 3.6

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/64733f0f-3caf-4637-9280-a0f9324b3a72%40googlegroups.com.

Robert Flatt

unread,
Apr 28, 2020, 3:42:45 PM4/28/20
to Kivy users support
3.7 (2019.10.6) worked for me, but I used p4a standalone, other poster here seems to have had trouble doing this with Buildozer - I don't know why.
You can look back thru the p4a releases to find one that uses 3.6, but going that far back you are pretty much guaranteed to have other issue.

What package are you having an issue with?
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/64733f0f-3caf-4637-9280-a0f9324b3a72%40googlegroups.com.

Dilshad khan

unread,
Apr 29, 2020, 8:25:11 AM4/29/20
to kivy-...@googlegroups.com
Dear Robert,

Sharing my code with you. This is example case of kivy. 

Thank you

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7b327501-3d0c-436c-a273-fd5a4fcafb46%40googlegroups.com.
main.py

Wilson Mutebi

unread,
Apr 29, 2020, 12:51:42 PM4/29/20
to kivy-...@googlegroups.com
I also want to know if at all you are using mysql_connector since this installs an old mysql connector

Robert Flatt

unread,
Apr 29, 2020, 1:13:37 PM4/29/20
to Kivy users support
Please cut this down to the smallest example that illustrates the issue.

Thank you

Robert Flatt

unread,
Apr 29, 2020, 1:22:52 PM4/29/20
to Kivy users support
I also want to know if at all you are using mysql_connector since this installs an old mysql connector

I'm sorry, I don't understand the comment.

What does 'this' in the post refer to?
And how is this related to weakref errors?

My understanding is that msql_connector is standalone installed from mysql see https://www.w3schools.com/python/python_mysql_getstarted.asp

Personally for db assess I use the Python package mysqlclient, though I have not tried this on Android.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/64733f0f-3caf-4637-9280-a0f9324b3a72%40googlegroups.com.

Robert Flatt

unread,
Apr 30, 2020, 2:27:20 AM4/30/20
to Kivy users support
I realized I don't know what you expect from posting your code.

I think perhaps I used p4a directly when looking at this issue, but I don't know if this would help you because I don't know the cause of your issue.
Another thing to try would be to go back to the default p4a in Buildozer (and clean) and set requirements kivy==2.0.0rc1

Also did you try either of these two options to work around the issue?
Reply all
Reply to author
Forward
0 new messages