Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setproctitle if available to show state #696

Merged
merged 6 commits into from Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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