From 20353df6527d4d16029700d7ae68a4b72a46cd31 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 20 Feb 2014 22:54:33 +0100 Subject: sigusr1 for reloading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/__main__.py b/src/__main__.py index 6aa0e2a..405bd76 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -31,7 +31,7 @@ PROGRAM_VERSION = '1.1' ## Set global variables global DATADIR, i_size, o_size, r_curve, g_curve, b_curve, clip_result, reset, panicgate global periodically, wait_period, fadein_time, fadeout_time, fadein_steps, fadeout_steps -global monitor_controller, running, continuous_run, panic +global monitor_controller, running, continuous_run, panic, _globals_ global signal_SIGTERM @@ -153,6 +153,26 @@ def signal_SIGTERM(signum, frame): running = False + +_globals_, _locals_ = globals(), dict(locals()) +for key in _locals_: + _globals_[key] = _locals_[key] +def signal_SIGUSR1(signum, frame): + ''' + Signal handler for SIGUSR1 + + @param signum The signal number, 0 if called from the program itself + @param frame Ignore, it will probably be `None` + ''' + code = None + with open(config_file, 'rb') as script: + code = script.read() + code = code.decode('utf8', 'error') + '\n' + code = compile(code, config_file, 'exec') + exec(code, _globals_) + + + def continuous_run(): ''' Invoked to run continuously if `periodically` is not `None` @@ -172,6 +192,7 @@ def continuous_run(): ## Catch signals signal.signal(signal.SIGTERM, signal_SIGTERM) + signal.signal(signal.SIGUSR1, signal_SIGUSR1) ## Fade in early_exit = False -- cgit v1.2.3-70-g09d2