Skip to content

Commit a99bc47

Browse files
authored
Fix resource warnings thanks to PDM (#68)
* Run Azure tests in python development mode * Fix identified resource leaks
2 parents 628f51e + be46388 commit a99bc47

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ History
55
2.3.0 (????-??-??)
66
------------------
77
* Python 3.6+ only, support for Python 3.5 has been dropped
8+
* Fix a file descriptor leak on subprocess execution
89

910
2.2.0 (2020-09-07)
1011
------------------

procrunner/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def _thread_write_stream_to_buffer():
132132
else:
133133
if self._closing:
134134
break
135+
self._stream.close()
135136
self._terminated = True
136137
la.flush()
137138
if self._debug:
@@ -151,6 +152,7 @@ def _thread_write_stream_to_buffer_windows():
151152
print(linedecode)
152153
if callback:
153154
callback(linedecode)
155+
self._stream.close()
154156
self._terminated = True
155157
if self._debug:
156158
logger.debug("Stream reader terminated")

tests/test_procrunner_system.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def test_running_wget(tmp_path):
5656
def test_path_object_resolution(tmp_path):
5757
sentinel_value = b"sentinel"
5858
tmp_path.joinpath("tempfile").write_bytes(sentinel_value)
59-
tmp_path.joinpath("reader.py").write_text("print(open('tempfile').read())")
59+
tmp_path.joinpath("reader.py").write_text(
60+
"with open('tempfile') as fh:\n print(fh.read())"
61+
)
6062
assert "LEAK_DETECTOR" not in os.environ
6163
result = procrunner.run(
6264
[sys.executable, tmp_path / "reader.py"],

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ deps =
1414
pytest-azurepipelines
1515
pytest-cov
1616
-r{toxinidir}/requirements_dev.txt
17+
setenv =
18+
PYTHONDEVMODE = 1
1719
commands =
1820
pytest -ra --basetemp={envtmpdir} --cov=procrunner --cov-report=html --cov-report=xml --cov-branch
1921

0 commit comments

Comments
 (0)