kivy / kivy-ios

Toolchain for compiling Python / Kivy / other libraries for iOS
https://kivy.org/docs/guide/packaging-ios.html
MIT License
759 stars 238 forks source link

Segmentation fault: 11 | Threading not Working for Kivy iOS #696

Closed usMAEC closed 2 years ago

usMAEC commented 2 years ago

Versions

Describe the bug Segmentation fault 11 when trying to thread a function on Mac.

To Reproduce import time import threading

#This will take care of refreshing all of the things
def refreshAll(self):
    self.get_top_news()

stop = threading.Event()
def start_background(self):
    iteration = 0
    play = False
    if self.root.ids.play.text == 'Autoplay':
        self.root.ids.play.text = 'Playing'
        self.root.ids.play.icon = "autorenew"
        play = True
        # Start a new thread with an infinite loop and stop the current one.
        threading.Thread(target=self.infinite_loop).start()
    else:
        self.root.ids.play.text = 'Autoplay'
        self.root.ids.play.icon = "play"
        play = False
        self.on_stop()
def on_stop(self):
    self.stop.set()
def infinite_loop(self):
    while True:
        if self.stop.is_set():
            # Stop running this thread so the main Python process can exit.
            print("Congrats loop stopped")
            return
        self.refreshAll()
        self.iteration += 1
        print("running every:")
        print(30)

Expected behavior Loop/ function working on the background.

Logs

INFO   ] [Base        ] Start application main loop
Successfully logged a user in automatically using the refresh token
Testing True in
self.login_success= True
User has logged in. Unique identifier is  

Segmentation fault: 11

Additional context I am trying to get a function to run on the background and it has worked for me on linux and android yet on iOS or Mac I get a segmentation fault 11 and the app crashes.

tito commented 2 years ago

Threads works. What doesn't work is anything in thread that would call a OpenGL function. So if in your refreshAll, you change anything in the UI (direct call, or from a binding of your data to your UI), then it can crash.

Ref: https://github.com/kivy/kivy/wiki/Working-with-Python-threads-inside-a-Kivy-application