From 0b648521fd0a5b3c9c9f54a89b18f24935fac46f Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 5 Dec 2018 02:17:17 -0500 Subject: [PATCH] Move setproctitle() stuff into title.py. This removes another instance of magical code running at module import time. And the process title wasn't really part of the state database anyway. Unfortunately this uncovered a bug: the recent change to use 'python -S' makes it not find the setproctitle module if installed. My goodness, I hate the horrible python easy_install module gunk that makes startup linearly slower the more modules you have installed, whether you import them or not, if you don't use -S. But oh well, we're stuck with it for now. --- bin/default.do | 4 +++- redo/state.py | 11 ----------- redo/title.py | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 redo/title.py diff --git a/bin/default.do b/bin/default.do index 048e976..9d5af0a 100644 --- a/bin/default.do +++ b/bin/default.do @@ -18,13 +18,15 @@ case $1 in read py <../redo/whichpython cmd=${1#redo-} cat >$3 <<-EOF - #!$py -S + #!$py import sys, os; exe = os.path.realpath(os.path.abspath(sys.argv[0])) exedir = os.path.dirname(exe) sys.path.insert(0, os.path.join(exedir, '../lib')) sys.path.insert(0, os.path.join(exedir, '..')) + import redo.title import redo.cmd_$cmd + redo.title.auto() redo.cmd_$cmd.main() EOF chmod a+x "$3" diff --git a/redo/state.py b/redo/state.py index 7fbf6ab..f05107e 100644 --- a/redo/state.py +++ b/redo/state.py @@ -3,17 +3,6 @@ import cycles, env from helpers import unlink, close_on_exec, join from logs import warn, debug2, debug3 -# When the module is imported, change the process title. -# We do it here because this module is imported by all the scripts. -try: - from setproctitle import setproctitle -except ImportError: - pass -else: - cmdline = sys.argv[:] - cmdline[0] = os.path.splitext(os.path.basename(cmdline[0]))[0] - setproctitle(" ".join(cmdline)) - SCHEMA_VER = 2 TIMEOUT = 60 diff --git a/redo/title.py b/redo/title.py new file mode 100644 index 0000000..8cdf40d --- /dev/null +++ b/redo/title.py @@ -0,0 +1,17 @@ +import os, sys + +# FIXME: setproctitle module is only usable if *not* using python -S, +# and without -S, python startup time is annoyingly longer +try: + from setproctitle import setproctitle +except ImportError: + def setproctitle(name): + pass + + +def auto(): + """Automatically clean up the title as seen by 'ps', based on argv.""" + exe = sys.argv[0] + exename, ext = os.path.splitext(os.path.basename(sys.argv[0])) + title = ' '.join([exename] + sys.argv[1:]) + setproctitle(title)