Skip to content

FlyingThings3D test is flaky on Windows #7626

Open
@pmeier

Description

@pmeier

I've recently seen an error like below pop up a few times in Windows CI:

Traceback (most recent call last):
  File "C:\actions-runner\_work\vision\vision\pytorch\vision\test\datasets_utils.py", line 531, in test_feature_types
    with self.create_dataset(config) as (dataset, _):
  File "C:\Jenkins\Miniconda3\envs\ci\lib\contextlib.py", line 142, in __exit__
    next(self.gen)
  File "C:\actions-runner\_work\vision\vision\pytorch\vision\test\datasets_utils.py", line 617, in create_dataset
    with super().create_dataset(
  File "C:\Jenkins\Miniconda3\envs\ci\lib\contextlib.py", line 142, in __exit__
    next(self.gen)
  File "C:\actions-runner\_work\vision\vision\pytorch\vision\test\datasets_utils.py", line 371, in create_dataset
    with get_tmp_dir() as tmpdir:
  File "C:\Jenkins\Miniconda3\envs\ci\lib\contextlib.py", line 142, in __exit__
    next(self.gen)
  File "C:\actions-runner\_work\vision\vision\pytorch\vision\test\common_utils.py", line 47, in get_tmp_dir
    shutil.rmtree(tmp_dir)
  File "C:\Jenkins\Miniconda3\envs\ci\lib\shutil.py", line 750, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Jenkins\Miniconda3\envs\ci\lib\shutil.py", line 615, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Jenkins\Miniconda3\envs\ci\lib\shutil.py", line 615, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Jenkins\Miniconda3\envs\ci\lib\shutil.py", line 615, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  [Previous line repeated 2 more times]
  File "C:\Jenkins\Miniconda3\envs\ci\lib\shutil.py", line 624, in _rmtree_unsafe
    onerror(os.rmdir, path, sys.exc_info())
  File "C:\Jenkins\Miniconda3\envs\ci\lib\shutil.py", line 622, in _rmtree_unsafe
    os.rmdir(path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpruvdnq3j\\FlyingThings3D\\frames_cleanpass\\TRAIN\\B\\0001'

This can happen on Windows if we open a file, but not close it before the test ends. We have a patch for PIL images to always load them properly

# PIL.Image.open() only loads the image metadata upfront and keeps the file open until the first access
# to the pixel data occurs. Trying to delete such a file results in an PermissionError on Windows. Thus, we
# force-load opened images.
# This problem only occurs during testing since some tests, e.g. DatasetTestCase.test_feature_types open an
# image, but never use the underlying data. During normal operation it is reasonable to assume that the
# user wants to work with the image he just opened rather than deleting the underlying file.
with self._force_load_images():
yield dataset, info
@contextlib.contextmanager
def _force_load_images(self):
open = PIL.Image.open
def new(fp, *args, **kwargs):
image = open(fp, *args, **kwargs)
if isinstance(fp, (str, pathlib.Path)):
image.load()
return image
with unittest.mock.patch("PIL.Image.open", new=new):
yield

Meaning, either that doesn't work or another file type is causing this.

cc @peterjc123 @nbcsm @guyang3532 @maxluk @gunandrose4u @mszhanyi @seemethere

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions