问题
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