Multiprocessing to separate Photobooth logic and GUI. Pipes to connect them to each other

This commit is contained in:
Balthasar Reuter
2018-03-21 22:09:37 +01:00
parent 65c70f6fc4
commit 0688fa5fa6
2 changed files with 174 additions and 21 deletions

View File

@@ -1,9 +1,63 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import Config, PyQt5Gui
from Config import Config
from PyQt5Gui import PyQt5Gui
from multiprocessing import Pipe, Process
from time import sleep
class Photobooth:
def __init__(self):
pass
def run(self, send, recv):
while True:
try:
event = recv.recv()
except EOFError:
return 1
else:
print('Photobooth: ' + event)
self.trigger(send)
return 0
def trigger(self, send):
send.send('Pose')
sleep(3)
send.send('Picture')
sleep(2)
send.send('idle')
def main_photobooth(send, recv):
photobooth = Photobooth()
return photobooth.run(send, recv)
def main(argv):
config = Config.Config('photobooth.cfg')
return PyQt5Gui.run(argv, config)
config = Config('photobooth.cfg')
event_recv, event_send = Pipe(duplex=False)
gui_recv, gui_send = Pipe(duplex=False)
photobooth = Process(target=main_photobooth, args=(gui_send, event_recv), daemon=True)
photobooth.start()
gui = PyQt5Gui(argv, config)
return gui.run(event_send, gui_recv)