From a30e41f0b42c51c9943b73492ee3aef8346f46d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 28 Dec 2014 00:12:19 +0100 Subject: [PATCH] Timelapses: Do not try to use image counter if still set to None and synchronize decrementing of image counter via mutex as well Possible fixes for #693, the latter maybe also for #690 --- CHANGELOG.md | 12 ++++++++++++ src/octoprint/timelapse.py | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58e4a7c5..e12f3ae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,23 @@ ## 1.1.2 (Unreleased) +### Improvements + +* Added deletion of `*.pyc` files to `python setup.py clean` command, should help tremendously when switching branches (backported + from [9e014eb](https://github.com/foosel/OctoPrint/commit/9e014eba1feffde11ed0601d9c911b8cac9f3fb0)) + ### Bug Fixes * [#634](https://github.com/foosel/OctoPrint/pull/634) - Fixed missing `branch` fields in version dicts generated by versioneer * [IRC] Don't hiccup on slic3r filament_diameter comments generated for multi extruder setups +* Small fixes for timelapse creation: + - [#344](https://github.com/foosel/OctoPrint/issues/344) - Made timelapses capable of coping with missing captures in between by decrementing the image counter again if there + was an error fetching the latest image from the snapshot URL (backport of [1a7a468](https://github.com/foosel/OctoPrint/commit/1a7a468eb65fdf2a13b4c7a7723280e822c9c34b) + and [bf9d5ef](https://github.com/foosel/OctoPrint/commit/bf9d5efe43a1e57aacd8512125082ddca06b4efc)) + - [#693](https://github.com/foosel/OctoPrint/issues/693) - Try not to capture an image if image counter is still unset + - [unreported] Synchronize image counter decrementing as well as incrementing to prevent rare race conditions when generating the + image file names ## 1.1.1 (2014-10-27) diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index 5474a4d3..c27fb1a9 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -226,8 +226,12 @@ class Timelapse(object): self._logger.warn("Cannot capture image, capture directory is unset") return + if self._imageNumber is None: + self._logger.warn("Cannot capture image, image number is unset") + return + with self._captureMutex: - filename = os.path.join(self._captureDir, "tmp_%05d.jpg" % (self._imageNumber)) + filename = os.path.join(self._captureDir, "tmp_%05d.jpg" % self._imageNumber) self._imageNumber += 1 self._logger.debug("Capturing image to %s" % filename) captureThread = threading.Thread(target=self._captureWorker, kwargs={"filename": filename}) @@ -242,7 +246,8 @@ class Timelapse(object): self._logger.debug("Image %s captured from %s" % (filename, self._snapshotUrl)) except: self._logger.exception("Could not capture image %s from %s, decreasing image counter again" % (filename, self._snapshotUrl)) - self._imageNumber -= 1 + with self._captureMutex: + self._imageNumber -= 1 eventManager().fire(Events.CAPTURE_DONE, {"file": filename}) def _createMovie(self, success=True):