Kivy app running as a background thread

799 views
Skip to first unread message

RedDevil91

unread,
Apr 25, 2016, 3:17:20 AM4/25/16
to Kivy users support
Hi!

I am working on a software upgrade at work and I want to replace pyglet with kivy in our software. The problem is that pyglet's event loop is running as a background thread in our application.
I tried to run kivy app as a background thread but it always crashed. Is there a solution to run it as a background thread?

RedDevil91

Alexander Taylor

unread,
Apr 25, 2016, 6:34:11 AM4/25/16
to Kivy users support
I think (without having tried it) that this should be possible, but you might have to be careful about e.g making sure all opengl happens in that thread. Kivy comes with an IteractiveLauncher that's somewhat broken right now, but does in principle do this fine.

If you post deails of the problem, people may be able to help with the specifics.

RedDevil91

unread,
Apr 25, 2016, 9:53:29 AM4/25/16
to Kivy users support
Fortunately I managed to do it. I only had to import my root widget's class from the main app's build method. In the following code AppBase is my root widget, MyApp is my main app and back_thread is the background thread.

class MyApp(App):
    def build(self):
        from Appbase import AppBase
        base = AppBase()
        return base

def run_app():
    app = MyApp()
    app.run()

if __name__ == '__main__':
    back_thread = threading.Thread(target=run_app)
    back_thread.setDaemon(True)
    back_thread.start()
Reply all
Reply to author
Forward
0 new messages