From adbaaf38cefb4dbdab6e2aaea740f17f462cd26e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 11 Oct 2018 08:43:59 +0100 Subject: [PATCH] Use py-setproctitle to clean up ps output in redo scripts * Change the process title with a cleaned-up version of the script * Document the use of setproctitle in the README --- README.md | 23 +++++++++++------------ state.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0b257a8..b54c80b 100644 --- a/README.md +++ b/README.md @@ -1414,21 +1414,20 @@ use of them.) # The output of 'ps ax' is ugly because of the python interpreter! -FIXME: -Yes, this is a general problem with python. All the lines -in 'ps' end up looking like +If the [setproctitle](http://code.google.com/p/py-setproctitle/) module is +installed, redo will use it in its script to clean up the displayed title. The +module is also available in many distributions. A `ps xf` output would look +like: - 28460 pts/2 Sl 0:00 /usr/bin/python /path/to/redo-ifchange stuff... + ... + 23461 pts/21 T 0:00 \_ make test + 23462 pts/21 T 0:00 | \_ redo test + 23463 pts/21 T 0:00 | \_ sh -e test.do test test test.redo2.tmp + 23464 pts/21 T 0:00 | \_ redo-ifchange _all + 23465 pts/21 T 0:00 | \_ sh -e _all.do _all _all _all.redo2.tmp + ... -...which means that the "stuff..." part is often cut off on -the right hand side. There are gross workarounds to fix -this in python, but the easiest fix will be to just rewrite -redo in C. Then it'll look like this: - 28460 pts/2 Sl 0:00 redo-ifchange stuff... - -...the way it should. - # Are there examples? diff --git a/state.py b/state.py index 85536de..354a5b2 100644 --- a/state.py +++ b/state.py @@ -3,6 +3,17 @@ import vars from helpers import unlink, close_on_exec, join from log import warn, err, 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=1 TIMEOUT=60