최소의 작동 예제는 황금 표준이며 현재 작업 중입니다. 그러나 명백한 오류가있을 수 있습니다. 함수 run_worker
은 버튼 누름 이벤트시 실행됩니다. 클래스 인스턴스를 초기화하고 해당 클래스의 메소드를 시작해야합니다. 그러나 run_worker 함수는 클래스 메서드가 완료 될 때까지 대기합니다. 결과적으로 kivy는 멈추고 다른 것들은 할 수 없습니다. 이 경우 멀티 프로세싱을 어떻게 사용해야합니까?다중 처리 : 프로세스가 끝날 때까지 주 프로그램이 멈 춥니 다.
from multiprocessing import Process
class SettingsApp(App):
""" Short not working version of the actual programm
"""
def build(self):
"""Some kivy specific settings"""
return Interface
"""This part does not work as expected. It is run by pushing a button. However, The function does hang until the Process has finished (or has been killed)."""
def run_worker(self):
"""The pHBot application is started as a second process. Otherwise kivy would be blocked until the function stops
(which is controlled by the close button)
"""
# get the arguments in appropriate form
args = self.get_stored_settings()
# Initiate the class which should be run by a separate process
bot = pHBot(*args)
# the control method runs some devices, listens to sensors etc.
phbot = Process(target=bot.ph_control(), args=(bot,))
# start the process
phbot.start()
# This statement is executed only after phbot has stopped.
print('Started')
실제 사례가 필요합니다. –
'ph_control'이 함수를 반환합니까? Process 객체를 생성하기도 전에 호출하기 때문에 바인딩 된 메소드처럼 'args'에'bot' 인수가 필요 없을 것입니다. pHBot이 다른 프로세스에서 작동 할 때 기대하는 바를 수행하는지 여부는 또 다른 질문입니다. 이런 종류의 동작으로 이어지는 또 다른 공통적 인 문제는 단지 출력을 플러시하지 않는 것입니다 ('sys.stdout.flush()'). 그러나 나는 그것이 이번이라고 생각하지 않습니다. –