Skip to content

Close the traceback cache file - #86

Open
hilman2 wants to merge 1 commit into
CheetahTemplate3:masterfrom
hilman2:fix-unclosed-file
Open

Close the traceback cache file#86
hilman2 wants to merge 1 commit into
CheetahTemplate3:masterfrom
hilman2:fix-unclosed-file

Conversation

@hilman2

@hilman2 hilman2 commented Aug 26, 2026

Copy link
Copy Markdown

open(__file__, 'w').write(generatedModuleCode) in Template.compile leaves the file object open. CPython closes it by refcount and emits a ResourceWarning; on PyPy the file can be left empty or truncated, which defeats the feature it implements.

The call sits in a try whose finally releases _CHEETAH_compileLock, so a write failure released the lock and left a partial file behind.

CPython's refcounting hides this, so the test in Tests/Template.py covers that the file is written completely rather than reproducing the leak. Full suite passes on 2.7, 3.6 and 3.12, flake8 clean.

`open(__file__, 'w').write(generatedModuleCode)` leaves the file
object open. CPython closes it by refcount soon after, with a
ResourceWarning; on PyPy the file can be left empty or truncated,
which defeats the feature it implements.

The call also sits in a try whose finally releases
_CHEETAH_compileLock, so a write failure released the lock and left a
partial file behind.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

2 participants