From 1997a8989f59c1d12b380ac1a43e3e4adad21588 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Mon, 16 Jul 2018 23:30:14 +0200 Subject: [PATCH] Worker moved into own module, cleaned up process termination --- photobooth/gui/Qt5Gui/PyQt5Gui.py | 2 ++ photobooth/main.py | 20 ++++++-------------- photobooth/{ => worker}/PictureList.py | 0 photobooth/{Worker.py => worker/__init__.py} | 4 ++-- 4 files changed, 10 insertions(+), 16 deletions(-) rename photobooth/{ => worker}/PictureList.py (100%) rename photobooth/{Worker.py => worker/__init__.py} (98%) diff --git a/photobooth/gui/Qt5Gui/PyQt5Gui.py b/photobooth/gui/Qt5Gui/PyQt5Gui.py index 939222b..3e0315d 100644 --- a/photobooth/gui/Qt5Gui/PyQt5Gui.py +++ b/photobooth/gui/Qt5Gui/PyQt5Gui.py @@ -130,6 +130,8 @@ class PyQt5Gui(GuiSkeleton): if state.target == TeardownEvent.WELCOME: self._comm.send(Workers.MASTER, GuiEvent('welcome')) + elif state.target in (TeardownEvent.EXIT, TeardownEvent.RESTART): + self._app.exit(0) def showError(self, state): diff --git a/photobooth/main.py b/photobooth/main.py index b4ba397..0f3f38b 100644 --- a/photobooth/main.py +++ b/photobooth/main.py @@ -33,7 +33,7 @@ from .Config import Config from .util import lookup_and_import from .StateMachine import Context, ErrorEvent from .Threading import Communicator, Workers -from .Worker import Worker +from .worker import Worker class CameraProcess(mp.Process): @@ -107,16 +107,11 @@ def run(argv): comm = Communicator() context = Context(comm) - # Create communication objects: - # 1. We use a pipe to connect GUI and camera process - # 2. We use a queue to feed tasks to the postprocessing process - # gui_conn, camera_conn = mp.Pipe() - # worker_queue = mp.SimpleQueue() - - # Initialize processes: We use three processes here: + # Initialize processes: We use four processes here: # 1. Camera processing # 2. Postprocessing # 3. GUI + # 4. Master camera_proc = CameraProcess(config, comm) # camera_conn, worker_queue) camera_proc.start() @@ -131,15 +126,12 @@ def run(argv): if exit_code in (0, 123): break - # Close endpoints - # gui_conn.close() - # camera_conn.close() - # Wait for processes to finish gui_proc.join() - # worker_queue.put('teardown') worker_proc.join() - camera_proc.join(1) + camera_proc.join() + logging.debug('All processes joined, returning code {}'. format(exit_code)) + return exit_code diff --git a/photobooth/PictureList.py b/photobooth/worker/PictureList.py similarity index 100% rename from photobooth/PictureList.py rename to photobooth/worker/PictureList.py diff --git a/photobooth/Worker.py b/photobooth/worker/__init__.py similarity index 98% rename from photobooth/Worker.py rename to photobooth/worker/__init__.py index 37a5575..176f4eb 100644 --- a/photobooth/Worker.py +++ b/photobooth/worker/__init__.py @@ -23,8 +23,8 @@ import os.path from time import localtime, strftime from .PictureList import PictureList -from . import StateMachine -from .Threading import Workers +from .. import StateMachine +from ..Threading import Workers class WorkerTask: