From: Calin Crisan Date: Sat, 27 Sep 2014 11:23:09 +0000 (+0300) Subject: don't allow cleanup and thumbnailer processes to run at the same time X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=31b7de32800dd4bcc02934c2c63954bd4129fb29;p=motioneye-debian don't allow cleanup and thumbnailer processes to run at the same time --- diff --git a/.gitignore b/.gitignore index 13041b9..3be82e4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ settings.py conf run -media \ No newline at end of file +media +log \ No newline at end of file diff --git a/src/cleanup.py b/src/cleanup.py index c51df08..3355af2 100644 --- a/src/cleanup.py +++ b/src/cleanup.py @@ -24,6 +24,7 @@ import tornado import mediafiles import settings +import thumbnailer _process = None @@ -53,17 +54,25 @@ def stop(): def running(): - return _process is not None + return _process is not None and _process.is_alive() def _run_process(): global _process - # schedule the next call ioloop = tornado.ioloop.IOLoop.instance() - ioloop.add_timeout(datetime.timedelta(seconds=settings.CLEANUP_INTERVAL), _run_process) + + if thumbnailer.running(): + # postpone if thumbnailer is currently running + ioloop.add_timeout(datetime.timedelta(seconds=60), _run_process) + + return + + else: + # schedule the next call + ioloop.add_timeout(datetime.timedelta(seconds=settings.CLEANUP_INTERVAL), _run_process) - if not _process or not _process.is_alive(): # check that the previous process has finished + if not running(): # check that the previous process has finished logging.debug('running cleanup process...') _process = multiprocessing.Process(target=_do_cleanup) diff --git a/src/thumbnailer.py b/src/thumbnailer.py index 8103784..c702863 100644 --- a/src/thumbnailer.py +++ b/src/thumbnailer.py @@ -22,6 +22,7 @@ import os import signal import tornado +import cleanup import mediafiles import settings @@ -53,7 +54,7 @@ def stop(): def running(): - return _process is not None + return _process is not None and _process.is_alive() def _run_process(): @@ -63,7 +64,7 @@ def _run_process(): ioloop = tornado.ioloop.IOLoop.instance() ioloop.add_timeout(datetime.timedelta(seconds=settings.THUMBNAILER_INTERVAL), _run_process) - if not _process or not _process.is_alive(): # check that the previous process has finished + if not running() and not cleanup.running(): # check that the previous process has finished and that cleanup is not running logging.debug('running thumbnailer process...') _process = multiprocessing.Process(target=_do_next_movie_thumbail)