From d392bb7be00170002741098d826f77473552f914 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 25 Mar 2014 09:20:23 +0100 Subject: Appearently we can interrupt datetime.datetime.now MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/__main__.py b/src/__main__.py index 1da6f96..804b68c 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -259,6 +259,12 @@ def continuous_run(): time.sleep(seconds) # setitimer may not be supported except KeyboardInterrupt: signal_SIGTERM(0, None) + def now(): + while True: + try: + return datetime.datetime.now() + except KeyboardInterrupt: + signal_SIGTERM(0, None) ## Catch signals def signal_(sig, fun): @@ -278,7 +284,7 @@ def continuous_run(): while running: if trans_delta == 0: ## Run periodically - p(datetime.datetime.now(), None) + p(now(), None) if running: sleep(wait_period) elif trans_delta < 0: @@ -287,13 +293,13 @@ def continuous_run(): fadein_time = None if not ((fadein_time is None) or panicgate): if trans_alpha == 0: - p(datetime.datetime.now(), 1 - trans_alpha) + p(now(), 1 - trans_alpha) sleep(fadein_time / fadein_steps) trans_alpha -= 1 / fadein_steps if (trans_alpha <= 0) or (fadein_time is None) or panicgate: trans_alpha = 0 trans_delta = 0 - p(datetime.datetime.now(), 1 - trans_alpha) + p(now(), 1 - trans_alpha) if fadein_time is not None: sleep(fadein_time / fadein_steps) else: @@ -304,7 +310,7 @@ def continuous_run(): trans_alpha += 1 / fadeout_steps if (trans_alpha >= 1) or (fadeout_time is None): trans_alpha = 1 - p(datetime.datetime.now(), -1 + trans_alpha) + p(now(), -1 + trans_alpha) if trans_alpha == 1: try: with sleep_condition: @@ -324,7 +330,7 @@ def continuous_run(): if (trans_alpha >= 1) or (fadeout_time is None): trans_alpha = 1 panic = True - p(datetime.datetime.now(), -1 + trans_alpha) + p(now(), -1 + trans_alpha) sleep(fadeout_time / fadeout_steps) ## Reset -- cgit v1.2.3-70-g09d2