Why Kivy doesn't allow multiprocessing precess to terminate in Python?

烈酒焚心 提交于 2021-01-29 13:29:12

问题


I'm creating my first app, and I've found this problem with Kivy:

When I use multiprocessing in a Kivy app, the processes I created are immune to ".terminate()". Same code, but outside an app, works fine. What am I doing wrong?

Here I attach some code:

    from kivy.app import App
    from kivy.lang import Builder
    from kivy.uix.screenmanager import Screen
    import multiprocessing
    import time
    from plyer import tts

    kv = Builder.load_file("testup.kv")

    class TestScreen(Screen):
        def speech(self):
            for i in range(10):
                tts.speak(f'{i+1}')
                time.sleep(0.5)

        def start_speech(self):
            self.timing_process = multiprocessing.Process(target=self.speech)
            self.timing_process.start()

        def stop_speech(self):
            self.timing_process.terminate()
            print("timing terminated")


    class TestUp(App):
        def build(self):
            return TestScreen()


    if __name__ == '__main__':
        TestUp().run()

来源:https://stackoverflow.com/questions/61287104/why-kivy-doesnt-allow-multiprocessing-precess-to-terminate-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!