Threads in kivy

495 views
Skip to first unread message

Liam O'Shaughnessy

unread,
Jun 15, 2015, 1:02:51 PM6/15/15
to kivy-...@googlegroups.com
Hi all. I have a relatively straightforward question.

If I have a function running in a new thread in kivy, will the class attributes that it updates be accessible in "real time" to the main thread?

Some background. I have a function which takes lots of time to run. So I decided to place it on a new thread, and then subsequently found out that I cannot update the GUI from a new thread (the update being a progress bar). 

Now I have been trying to do something along the lines of having a clock_schedule event updating the progress bar on the main thread, while the heavy function runs on the new thread and updates the value parameter for the progress bar.

Does this make sense? I'll readily admit that I don't fully understand threads, but if they work they way I think they do (which they might not!), this should work?

Alexander Taylor

unread,
Jun 15, 2015, 1:08:10 PM6/15/15
to kivy-...@googlegroups.com
Using the clock this way is the right approach. You can use the @mainthread decorator (http://kivy.org/docs/api-kivy.clock.html#kivy.clock.mainthread) to do this automatically.

Liam O'Shaughnessy

unread,
Jun 15, 2015, 3:36:39 PM6/15/15
to kivy-...@googlegroups.com

Thank you for the reply.

I have done this and it works nicely on the desktop,  but it crashes on android. Am I missing something here? As in, do I need to add something to my buildozer.spec file to enable threading or something like that?

niavlys

unread,
Jun 16, 2015, 8:47:49 AM6/16/15
to kivy-...@googlegroups.com


Le lundi 15 juin 2015 21:36:39 UTC+2, Liam O'Shaughnessy a écrit :
it crashes on android. Am I missing something here?


 are you using pyjnius inside your thread? see the caveat here:

http://pyjnius.readthedocs.org/en/latest/api.html#pyjnius-and-threads
Reply all
Reply to author
Forward
0 new messages