Skip to content

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Jul 1, 2020

Just a little leftover from trying to hunt down ResourceWarnings a few weeks ago.

No semantic changes intended.

def matching_platform(self):
def matching_platform(self) -> bool:
try:
subprocess.check_output(("lsof", "-v"))
Copy link
Member

Choose a reason for hiding this comment

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

just out of curiosity, why do you prefer run to check_output here?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no good reason, only that the subprocess docs start with describing only the run function and say

The run() function was added in Python 3.5; if you need to retain compatibility with older versions, see the Older high-level API section.

And that "Older high-level API" includes check_output. So I just use run for everything.

Copy link
Member

Choose a reason for hiding this comment

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

thanks for explaining @bluetech

Copy link
Member

@gnikonorov gnikonorov left a comment

Choose a reason for hiding this comment

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

approving since it looks good, but I am curious if we should maybe handle exceptions here if they are thrown


def _parse_lsof_output(self, out):
def isopen(line):
def get_open_files(self) -> List[Tuple[str, str]]:
Copy link
Member

Choose a reason for hiding this comment

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

why do we not handle any errors? Just curious since the original method doesn't seem to have done it either. But, it looks like it is possible for subprocess.run to throw at least CalledProcessError and TimeoutExpired.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I think it would be good to handle errors from the lsof call here.

If the lsof command doesn't exist, the LsofFdLeakChecker plugin isn't registered at all, so the issue can't be that lsof isn't found at all, but it can still return an error itself.

I don't think TimeoutExpired can happen because we don't pass timeout to subprocess.run, but CalledProcessError can happen.

Then there's a question what to do if an error occurs. I guess in this case the most reasonable thing is to just skip the check for the particular test, and issue a warning.

@bluetech bluetech merged commit 64dd700 into pytest-dev:master Jul 4, 2020
@bluetech
Copy link
Member Author

bluetech commented Jul 4, 2020

Thanks for reviewing @gnikonorov!

@bluetech bluetech deleted the cleanup-lsof branch July 14, 2020 07:16
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.

2 participants