diff --git a/dvc/daemon.py b/dvc/daemon.py index 6266d7a8b..2fd216b79 100644 --- a/dvc/daemon.py +++ b/dvc/daemon.py @@ -14,7 +14,14 @@ from dvc.utils import fix_env, is_binary logger = logging.getLogger(__name__) -def _popen(cmd, **kwargs): +def _suppress_resource_warning(popen: Popen): + """Sets the returncode to avoid ResourceWarning when popen is garbage collected.""" + # only use for daemon processes. + # See https://bugs.python.org/issue38890. + popen.returncode = 0 + + +def _popen(cmd, **kwargs) -> Popen: prefix = [sys.executable] if not is_binary(): main_entrypoint = os.path.join( @@ -40,7 +47,10 @@ def _spawn_windows(cmd, env): startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW - _popen(cmd, env=env, creationflags=creationflags, startupinfo=startupinfo) + popen = _popen( + cmd, env=env, creationflags=creationflags, startupinfo=startupinfo + ) + _suppress_resource_warning(popen) def _spawn_posix(cmd, env): diff --git a/dvc/stage/cache.py b/dvc/stage/cache.py index f5621b3b7..332059b0d 100644 --- a/dvc/stage/cache.py +++ b/dvc/stage/cache.py @@ -1,6 +1,5 @@ import logging import os -import tempfile from contextlib import contextmanager from typing import TYPE_CHECKING, List, Optional, Tuple @@ -167,9 +166,10 @@ class StageCache: COMPILED_LOCK_FILE_STAGE_SCHEMA(cache) path = self._get_cache_path(cache_key, cache_value) - parent = self.repo.cache.local.fs.path.parent(path) + local_fs = self.repo.cache.local.fs + parent = local_fs.path.parent(path) self.repo.cache.local.makedirs(parent) - tmp = tempfile.NamedTemporaryFile(delete=False, dir=parent).name + tmp = local_fs.path.join(parent, fs.utils.tmp_fname()) assert os.path.exists(parent) assert os.path.isdir(parent) dump_yaml(tmp, cache) diff --git a/pyproject.toml b/pyproject.toml index 1cf0eb615..8612f1d9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -132,6 +132,8 @@ profile = "black" [tool.pytest.ini_options] addopts = "-ra --cov-config pyproject.toml --dist worksteal" filterwarnings = [ + "error::ResourceWarning", + "error::pytest.PytestUnraisableExceptionWarning", "error::pytest_mock.PytestMockWarning", # remove when aiobotocore supports botocore>=1.29.13 "ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning",