Skip to content

Commit

Permalink
Use setproctitle if avaiable to show state
Browse files Browse the repository at this point in the history
setproctitle() changes the process name, particularly in top/ps output
on posix-y systems.  This is very useful to get some transparency on
what's going on, especially if a test starts taking a very long time or
straight up hangs.

This is strictly a "bonus goodie", if setproctitle is not available,
it's not used, and any errors are ignored silently.

Signed-off-by: David Lamparter <equinox@diac24.net>
  • Loading branch information
eqvinox committed Aug 25, 2021
1 parent a5c65dd commit e889c1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog/696.feature.rst
@@ -0,0 +1,2 @@
Use setproctitle() to indicate current worker state if correspondent package
is available. Absent package (or any errors) just continues unchanged.
20 changes: 20 additions & 0 deletions src/xdist/remote.py
Expand Up @@ -16,6 +16,21 @@

from _pytest.config import _prepareconfig, Config

try:
from setproctitle import setproctitle
except ImportError:

def setproctitle(title):
pass


def worker_title(title):
try:
setproctitle(title)
except Exception:
# changing the process name is very optional, no errors please
pass


class WorkerInteractor:
def __init__(self, config, channel):
Expand Down Expand Up @@ -85,9 +100,14 @@ def run_one_test(self, torun):
else:
nextitem = None

worker_title("[pytest-xdist running] %s" % item.nodeid)

start = time.time()
self.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
duration = time.time() - start

worker_title("[pytest-xdist idle]")

self.sendevent(
"runtest_protocol_complete", item_index=self.item_index, duration=duration
)
Expand Down

0 comments on commit e889c1e

Please sign in to comment.