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

Conversation

eqvinox
Copy link
Contributor

@eqvinox eqvinox commented Aug 25, 2021

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.

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>
@eqvinox eqvinox changed the title Use setproctitle if avaiable to show state Use setproctitle if available to show state Aug 25, 2021
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @eqvinox,

Thanks a lot for the contribution, we appreciate it!

I think we still need a few things before we can merge it:

  • We should configure an extras so users can install with pip install pytest-xdist[setproctitle], in case we want to pin compatible versions in the future. Probably just change:

    extras_require={"testing": ["filelock"], "psutil": ["psutil>=3.0"]},

    To:

    extras_require={"testing": ["filelock"], "psutil": ["psutil>=3.0"], "setproctitle": ["proctitle"]},
  • Add docs to the README, including the above extra and a quick paragraph about what it does (like you did in the PR description).

  • In tox.ini, we need to test with this package, which can be done in its own environment (similar to [testenv:py38-psutil]). Also configure CI to run this test environment on Linux.

A test would be good, but I can't think of a way to test this without going through complicated hoops, so I think we can skip that.

While the change is pretty trivial, all this is important to ensure we don't break things by accident later.

Finally, I did take a quick look, but can you double check if the same can be done using psutil (which we already have the option to use)?

@eqvinox
Copy link
Contributor Author

eqvinox commented Sep 1, 2021

@nicoddemus hope to have addressed all your comments. I couldn't really test the tox item since Debian only provides Python 3.7 and 3.9, installing 3.8 would've been a major hassle, sorry about that 😞.

Finally, I did take a quick look, but can you double check if the same can be done using psutil

psutil is a purely read-only interface for process listing, I double checked and it doesn't have this feature.

(Also, as a Linux low-level developer, I can tell you setproctitle() [the C function] has barely any relationship to ps-like functions. It works by writing the text to a "magic" location in the running process, it doesn't go through /proc or a special syscall or anything like that.)

@eqvinox
Copy link
Contributor Author

eqvinox commented Sep 1, 2021

A test would be good, but I can't think of a way to test this without going through complicated hoops, so I think we can skip that.

It might be possible with the combination of psutil and setproctitle, using the former to check back in on the latter. But it'd probably end up being super flaky with any number of uncontrollable external influences breaking it (e.g. some Linux security modules constrain process visibility in odd ways, or a prefix on the title might be enforced, or the title might be truncated to a rather short limit, or the process might not see its own title, etc…)

@nicoddemus
Copy link
Member

It might be possible with the combination of psutil and setproctitle, using the former to check back in on the latter. But it'd probably end up being super flaky with any number of uncontrollable external influences breaking it

Figured as much, thanks!

@nicoddemus nicoddemus merged commit 766e67c into pytest-dev:master Sep 3, 2021
@nicoddemus
Copy link
Member

Thanks again @eqvinox!

I will prepare a release soon (possibly today)

LucasLeRay pushed a commit to LucasLeRay/pytest-xdist that referenced this pull request Sep 20, 2021
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
@nicoddemus
Copy link
Member

Sorry for the delay, 2.4.0 has been released with this change. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants