Skip to content

Commit fc46f11

Browse files
committed
fix ResourceWarning on exit caused by periodic update subprocess (#2472)
1 parent 119c63e commit fc46f11

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

docs/changelog/2472.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed ResourceWarning on exit caused by periodic update subprocess

src/virtualenv/seed/wheels/periodic_update.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from itertools import groupby
1313
from pathlib import Path
1414
from shutil import copy2
15-
from subprocess import PIPE, Popen
15+
from subprocess import DEVNULL, Popen
1616
from textwrap import dedent
1717
from threading import Thread
1818
from urllib.error import URLError
@@ -216,7 +216,7 @@ def trigger_update(distribution, for_py_version, wheel, search_dirs, app_data, e
216216
.format(distribution, for_py_version, wheel_path, str(app_data), [str(p) for p in search_dirs], periodic),
217217
]
218218
debug = env.get("_VIRTUALENV_PERIODIC_UPDATE_INLINE") == "1"
219-
pipe = None if debug else PIPE
219+
pipe = None if debug else DEVNULL
220220
kwargs = {"stdout": pipe, "stderr": pipe}
221221
if not debug and sys.platform == "win32":
222222
kwargs["creationflags"] = CREATE_NO_WINDOW
@@ -230,6 +230,9 @@ def trigger_update(distribution, for_py_version, wheel, search_dirs, app_data, e
230230
)
231231
if debug:
232232
process.communicate() # on purpose not called to make it a background process
233+
else:
234+
# set the returncode here -> no ResourceWarning on main process exit if the subprocess still runs
235+
process.returncode = 0
233236

234237

235238
def do_update(distribution, for_py_version, embed_filename, app_data, search_dirs, periodic): # noqa: PLR0913

0 commit comments

Comments
 (0)