Skip to content

ResourceWarning: unclosed file <_io.BufferedReader name  #962

Closed
@WrrngnCode

Description

@WrrngnCode

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions