Skip to content
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

fix ResourceWarning on process exit (#2472) #2617

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2472.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ResourceWarning on exit caused by periodic update subprocess
7 changes: 5 additions & 2 deletions src/virtualenv/seed/wheels/periodic_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from itertools import groupby
from pathlib import Path
from shutil import copy2
from subprocess import PIPE, Popen
from subprocess import DEVNULL, Popen
from textwrap import dedent
from threading import Thread
from urllib.error import URLError
Expand Down Expand Up @@ -216,7 +216,7 @@ def trigger_update(distribution, for_py_version, wheel, search_dirs, app_data, e
.format(distribution, for_py_version, wheel_path, str(app_data), [str(p) for p in search_dirs], periodic),
]
debug = env.get("_VIRTUALENV_PERIODIC_UPDATE_INLINE") == "1"
pipe = None if debug else PIPE
pipe = None if debug else DEVNULL
kwargs = {"stdout": pipe, "stderr": pipe}
if not debug and sys.platform == "win32":
kwargs["creationflags"] = CREATE_NO_WINDOW
Expand All @@ -230,6 +230,9 @@ def trigger_update(distribution, for_py_version, wheel, search_dirs, app_data, e
)
if debug:
process.communicate() # on purpose not called to make it a background process
else:
# set the returncode here -> no ResourceWarning on main process exit if the subprocess still runs
process.returncode = 0


def do_update(distribution, for_py_version, embed_filename, app_data, search_dirs, periodic): # noqa: PLR0913
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/seed/wheels/test_periodic_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def test_trigger_update_no_debug(for_py_version, session_app_data, tmp_path, moc
)

assert args == ([sys.executable, "-c", cmd],)
expected = {"stdout": subprocess.PIPE, "stderr": subprocess.PIPE}
expected = {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
if sys.platform == "win32":
expected["creationflags"] = CREATE_NO_WINDOW
assert kwargs == expected
Expand Down
Loading