Skip to content

Conversation

@StructuralWizard
Copy link

The previous implementation of PartialCode could lead to a PermissionError on Windows 11. This was because NamedTemporaryFile by default is created with exclusive access and is deleted immediately upon closing. If Manim's Code class (the superclass of PartialCode) tried to open the file path while the NamedTemporaryFile object still held it open (or if it was reopened incorrectly), it would result in a permission denied error.

This commit modifies PartialCode to:

  1. Create the NamedTemporaryFile with delete=False.
  2. Explicitly close the file after writing content and before calling super().__init__.
  3. Use a try/finally block to ensure the temporary file is manually deleted with os.remove() after super().__init__ has finished, preventing leftover temporary files.

This ensures the file path is accessible to the Manim Code constructor on Windows and that temporary files are still cleaned up reliably.

I have tested the creation of intro.py and it works.

The previous implementation of PartialCode could lead to a PermissionError
on Windows. This was because NamedTemporaryFile by default is created
with exclusive access and is deleted immediately upon closing. If Manim's
Code class (the superclass of PartialCode) tried to open the file path
while the NamedTemporaryFile object still held it open (or if it was
reopened incorrectly), it would result in a permission denied error.

This commit modifies PartialCode to:
1. Create the NamedTemporaryFile with `delete=False`.
2. Explicitly close the file after writing content and before calling
   `super().__init__`.
3. Use a try/finally block to ensure the temporary file is manually
   deleted with `os.remove()` after `super().__init__` has finished,
   preventing leftover temporary files.

This ensures the file path is accessible to the Manim Code constructor
on Windows and that temporary files are still cleaned up reliably.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant