Skip to content

Replace which command subprocesses with shutil.which()#136

Open
bwoodsend wants to merge 1 commit intoasweigart:masterfrom
bwoodsend:which
Open

Replace which command subprocesses with shutil.which()#136
bwoodsend wants to merge 1 commit intoasweigart:masterfrom
bwoodsend:which

Conversation

@bwoodsend
Copy link
Copy Markdown

This fixes (hidden by default) warnings about the subprocesses' stdout/stderr handles not being closed before being garbage collected:

> PYTHONWARNINGS=always::Warning pytest
...
../../../home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81
  /home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81: ResourceWarning: unclosed file <_io.BufferedReader name=11>
    whichProc = subprocess.Popen(['which', 'scrot'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

../../../home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81
  /home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81: ResourceWarning: unclosed file <_io.BufferedReader name=13>
    whichProc = subprocess.Popen(['which', 'scrot'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

And it removes the awkwardness of minimal Linux environments that don't have which installed.

This fixes (hidden by default) warnings about the subprocesses'
stdout/stderr handles not being closed before being garbage collected:

    > PYTHONWARNINGS=always::Warning pytest
    ...
    ../../../home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81
      /home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81: ResourceWarning: unclosed file <_io.BufferedReader name=11>
        whichProc = subprocess.Popen(['which', 'scrot'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      Enable tracemalloc to get traceback where the object was allocated.
      See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

    ../../../home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81
      /home/brenainn/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pyscreeze/__init__.py:81: ResourceWarning: unclosed file <_io.BufferedReader name=13>
        whichProc = subprocess.Popen(['which', 'scrot'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      Enable tracemalloc to get traceback where the object was allocated.
      See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

And it removes the awkwardness of minimal Linux environments that don't
have `which` installed.
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.

1 participant