Skip to content

ResourceWarning: unclosed file <_io.BufferedReader name #962

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

Closed
WrrngnCode opened this issue Feb 22, 2024 · 2 comments
Closed

ResourceWarning: unclosed file <_io.BufferedReader name #962

WrrngnCode opened this issue Feb 22, 2024 · 2 comments

Comments

@WrrngnCode
Copy link
Contributor

ResourceWarning: unclosed file <_io.BufferedReader name error message when trying to destroy AppiumService via stop method:

/usr/lib/python3.8/subprocess.py:946: ResourceWarning: subprocess 16298 is still running
  _warn("subprocess %s is still running" % self.pid,
Object allocated at (most recent call last):
  File "...../.venv/lib/python3.8/site-packages/appium/webdriver/appium_service.py", lineno 196
    self._process = sp.Popen(args=args, stdout=stdout, stderr=stderr, env=env)
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name=7>
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name=9>

It seems to me that the stderr and stout file handles are not closed properly.
According to subprocess.Popen documentation process.communicate shall be callled in order to close the stdout and stderr file handles.

Environment

Appium Version: 2.5.1
Appium-Python-Client 3.1.0
selenium 4.15.2
Python3.8.10 on Ubuntu 20.04
node.js 20.11.1

Code To reproduce issue

self._process.terminate()

After self._process.terminate a call to Popen.communicate()](https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate) shall be made, which will close the file handles.

self._process.terminate()
self._process.communicate()
@mykola-mokhnach
Copy link
Contributor

Thanks for the report @WrrngnCode
Feel free to open a PR to address this issue

WrrngnCode added a commit to WrrngnCode/python-client that referenced this issue Feb 24, 2024
appium#962
add a Popen.communicate call after terminate to ensure that file stdout and sdterr file descriptors are closed properly.
@WrrngnCode
Copy link
Contributor Author

PR created: #965

KazuCocoa pushed a commit that referenced this issue Feb 24, 2024
…f subprocess.Popen process (#965)

#962
add a Popen.communicate call after terminate to ensure that file stdout and sdterr file descriptors are closed properly.
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

No branches or pull requests

3 participants