Skip to content

Close datasets in time-coding.rst to fix Windows doc build cleanup#11459

Closed
Aimwee wants to merge 1 commit into
pydata:mainfrom
Aimwee:fix-window-cleanup
Closed

Close datasets in time-coding.rst to fix Windows doc build cleanup#11459
Aimwee wants to merge 1 commit into
pydata:mainfrom
Aimwee:fix-window-cleanup

Conversation

@Aimwee

@Aimwee Aimwee commented Jul 19, 2026

Copy link
Copy Markdown

Description

Fixes issue #11458

The datasets opened using xr.open_dataset() in the time-coding.rst file are not explicitly closed. Given the pages run using jupyter-execute, a notebook processor, the returned Dataset objects are retained in memory by IPython's output history even though the objects aren't assigned to variables. Due to open_dataset not reading the entire file into memory, the underlying files stayed open, causing tempdir.cleanup() to fail with PermissionError on Windows.

This pull request addresses these concerns by assigning each opened dataset to a named variable and closing it immediately before tempdir.cleanup() runs.

I'm a macOS user and don't have access to a Windows environement, therefore I'm not able to reproduce the PermissionError or test the fixes on Windows. I would appreciate it if a maintainer, original creator of the issue, or a Windows user could verify these changes on their end. Thank you.

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.

    • I take responsibility for any AI-generated content in my PR.

      Tools: Claude - used to help diagnose the root cause of the issue. I reviewed and tested the changes using 'pixi run doc' and understand the changes made prior to submitting.

@rwkozar

rwkozar commented Jul 20, 2026

Copy link
Copy Markdown

I found this issue at SciPy 2026 and worked on it some with @VeckoTheGecko. We talked about individually closing each file, but the developers didn't like that solution because the open_dataset function is used many times throughout the .rst files, not just in time-coding.rst, and they didn't want to add closing code for each instance.

I did test out your solution, and it worked for the time-coding.rst file, but then the build just failed the next time a .rst file tried to close an open dataset. So it should work if applied throughout the .rst files.

An intermediate solution - we tried garbage collection yesterday, but it didn't work. I tried gc.collect() at the bottom instead of the for loop. The variable naming throughout the file that you added allowed garbage collection to work and prevented the error. I'm still not sure if @VeckoTheGecko would be ok with adding the variable naming to the .rst file since those additional variable namings would show up in the docs, and that isn't necessarily the command they want to show users.

@VeckoTheGecko

Copy link
Copy Markdown
Contributor

Thanks @rwkozar for the detailed summary of the situation.

I'm going to close this PR so that we can discuss a more durable solution in the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation build failing in Windows

4 participants