From aa87e6fc95f0c07091ab137ad3eb71e27a922546 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 6 Oct 2013 22:38:21 +0300 Subject: [PATCH] mjpg clients are now closed before stopping motion --- src/mjpgclient.py | 10 +++++++++- src/motionctl.py | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mjpgclient.py b/src/mjpgclient.py index 9280bdb..b0ac554 100644 --- a/src/mjpgclient.py +++ b/src/mjpgclient.py @@ -6,7 +6,7 @@ import socket from tornado import iostream import config - +import motionctl class MjpgClient(iostream.IOStream): @@ -94,6 +94,9 @@ class MjpgClient(iostream.IOStream): def get_jpg(camera_id): + if not motionctl.running(): + return None + if camera_id not in MjpgClient.clients: # TODO implement some kind of timeout before retry here logging.debug('creating mjpg client for camera id %(camera_id)s' % { @@ -113,3 +116,8 @@ def get_jpg(camera_id): return None return MjpgClient.last_jpgs.get(camera_id) + + +def close_all(): + for client in MjpgClient.clients.values(): + client.close() diff --git a/src/motionctl.py b/src/motionctl.py index 548330f..436b3f0 100644 --- a/src/motionctl.py +++ b/src/motionctl.py @@ -53,8 +53,12 @@ def start(): def stop(): + import mjpgclient + if not running(): raise Exception('motion is not running') + + mjpgclient.close_all() pid = _get_pid() if pid is not None: -- 2.39.5