Skip to content

Commit 652f927

Browse files
committed
Use setproctitle python module, when available. NFC
This makes the process listing easier to read as it just shows `emcc ..` rather than `python3 -E emcc.py`. On many/most systems this won't do anything because the module is not installed. I'm going to pass on writing a test for this for now.
1 parent f5c5bb1 commit 652f927

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ types-requests==2.32.0.20241016
1212
unittest-xml-reporting==3.2.0
1313
deadcode==2.3.1
1414
vulture==2.14
15+
setproctitle==1.3.7
1516

1617
# This version is mentioned in `site/source/docs/site/about.rst`.
1718
# Please keep them in sync.

tools/shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ def get_llvm_target():
621621

622622
def init():
623623
utils.set_version_globals()
624+
utils.set_process_title()
624625
setup_temp_dirs()
625626

626627

tools/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@
2727
logger = logging.getLogger('utils')
2828

2929

30+
def set_process_title():
31+
"""Remove the python prefix of the process title.
32+
33+
This makes the process listing easier to read as it just shows
34+
`emcc ..` rather than e.g. `python3 -E emcc.py ...`.
35+
36+
This code depends the `setproctitle` PiPi module which might
37+
not be installed. If the module cannot be loaded this function
38+
simply does nothing.
39+
"""
40+
try:
41+
import setproctitle
42+
except ImportError:
43+
return
44+
t = setproctitle.getproctitle()
45+
t = shlex.split(t)
46+
while t and not t[0].endswith('.py'):
47+
t.pop(0)
48+
if t:
49+
t[0] = os.path.splitext(t[0])[0]
50+
setproctitle.setproctitle(shlex.join(t))
51+
52+
3053
def run_process(cmd, check=True, input=None, *args, **kw):
3154
"""Runs a subprocess returning the exit code.
3255

0 commit comments

Comments
 (0)