From 6ad0c3f4e2aae833dc8bedbe2a28fb1c7690f724 Mon Sep 17 00:00:00 2001 From: Brian Watt Date: Thu, 20 Dec 2018 19:10:58 -0600 Subject: [PATCH] Fix TODO These may not get called after the end of the threading --- timelapse.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/timelapse.py b/timelapse.py index 0b4fe3b..50d26b9 100755 --- a/timelapse.py +++ b/timelapse.py @@ -2,13 +2,12 @@ import errno import os import sys -import threading +import time from datetime import datetime from time import sleep import yaml config = yaml.safe_load(open(os.path.join(sys.path[0], "config.yml"))) -image_number = 0 def create_timestamped_dir(dir): @@ -55,27 +54,20 @@ def set_camera_options(camera): def capture_image(): try: - global image_number - - # Set a timer to take another picture at the proper interval after this - # picture is taken. - if (image_number < (config['total_images'] - 1)): - thread = threading.Timer(config['interval'], capture_image).start() - # Start up the camera. camera = PiCamera() set_camera_options(camera) - # Capture a picture. - camera.capture(dir + '/image{0:05d}.jpg'.format(image_number)) - camera.close() + for image_number in range(config['total_images']): + # Capture a picture. + camera.capture(dir + '/image{0:05d}.jpg'.format(image_number)) - if (image_number < (config['total_images'] - 1)): - image_number += 1 - else: - print '\nTime-lapse capture complete!\n' - # TODO: This doesn't pop user into the except block below :(. - sys.exit() + # Sleep after taking a picture for the proper interval + time.sleep(config['interval']) + + # Done using the camera. + camera.close() + print '\nTime-lapse capture complete!\n' except KeyboardInterrupt, SystemExit: print '\nTime-lapse capture cancelled.\n'