Skip to content

Documentation build failing in Windows #11458

Description

@rwkozar

What happened?

When using pixi run doc to create documentation in Windows, time-coding.rst is aborting with a failure because the file tries to delete test-datetimes1.nc while windows thinks it is open. We tried using gc.collect() to force garbage collection and del _, and a using a sleep timer to ensure that the processes were complete, but none of those worked.

Switching from xr.open_dataset() to xr.load_dataset() prevents the problem, but may not be appropriate in this situation.

What did you expect to happen?

Ideally the docs should build in any environment; however, expecting users Windows users to use WSL or another method when developing may be acceptable, if covered in the contributing guide.

Minimal Complete Verifiable Example

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "xarray[complete]@git+https://github.com/pydata/xarray.git@main",
# ]
# ///
#
# This script automatically imports the development branch of xarray to check for issues.
# Please delete this header if you have _not_ tested this script with `uv run`!

import xarray as xr
xr.show_versions()
# your reproducer code ...

Steps to reproduce

No response

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

sphinx.errors.ExtensionError: Cell raised uncaught exception:
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:701, in _rmtree_unsafe(path, dir_fd, onexc)
    700 try:
--> 701     os.unlink(fullname)
    702 except FileNotFoundError:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'

During handling of the above exception, another exception occurred:

PermissionError                           Traceback (most recent call last)
Cell In[49], line 2
      1 # Cleanup
----> 2 tempdir.cleanup()

File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:975, in TemporaryDirectory.cleanup(self)
    973 def cleanup(self):
    974     if self._finalizer.detach() or _os.path.exists(self.name):
--> 975         self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)

File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:955, in TemporaryDirectory._rmtree(cls, name, ignore_errors, repeated)
    952         if not ignore_errors:
    953             raise
--> 955 _shutil.rmtree(name, onexc=onexc)

File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:852, in rmtree(path, ignore_errors, onerror, onexc, dir_fd)
    849                 exc_info = type(exc), exc, exc.__traceback__
    850             return onerror(func, path, exc_info)
--> 852 _rmtree_impl(path, dir_fd, onexc)

File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:705, in _rmtree_unsafe(path, dir_fd, onexc)
    703             continue
    704         except OSError as err:
--> 705             onexc(os.unlink, fullname, err)
    706 try:
    707     os.rmdir(path)

File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:930, in TemporaryDirectory._rmtree.<locals>.onexc(func, path, exc)
    927 _resetperms(path)
    929 try:
--> 930     _os.unlink(path)
    931 except IsADirectoryError:
    932     cls._rmtree(path, ignore_errors=ignore_errors)

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'

Extension error:
Cell raised uncaught exception:
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:701, in _rmtree_unsafe(path, dir_fd, onexc)
    700 try:
--> 701     os.unlink(fullname)
    702 except FileNotFoundError:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'

During handling of the above exception, another exception occurred:

PermissionError                           Traceback (most recent call last)
Cell In[49], line 2
      1 # Cleanup
----> 2 tempdir.cleanup()

File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:975, in TemporaryDirectory.cleanup(self)
    973 def cleanup(self):
    974     if self._finalizer.detach() or _os.path.exists(self.name):
--> 975         self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)

File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:955, in TemporaryDirectory._rmtree(cls, name, ignore_errors, repeated)
    952         if not ignore_errors:
    953             raise
--> 955 _shutil.rmtree(name, onexc=onexc)

File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:852, in rmtree(path, ignore_errors, onerror, onexc, dir_fd)
    849                 exc_info = type(exc), exc, exc.__traceback__
    850             return onerror(func, path, exc_info)
--> 852 _rmtree_impl(path, dir_fd, onexc)

File ~\python\xarray\.pixi\envs\doc\Lib\shutil.py:705, in _rmtree_unsafe(path, dir_fd, onexc)
    703             continue
    704         except OSError as err:
--> 705             onexc(os.unlink, fullname, err)
    706 try:
    707     os.rmdir(path)

File ~\python\xarray\.pixi\envs\doc\Lib\tempfile.py:930, in TemporaryDirectory._rmtree.<locals>.onexc(func, path, exc)
    927 _resetperms(path)
    929 try:
--> 930     _os.unlink(path)
    931 except IsADirectoryError:
    932     cls._rmtree(path, ignore_errors=ignore_errors)

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\rwkoz\\AppData\\Local\\Temp\\tmptpg6hhgw\\test-datetimes1.nc'

Anything else we need to know?

No response

Environment

Details

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions