Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_handle.close() is never called -- and it causes a bug!! #607

Closed
stxlvt opened this issue Nov 26, 2015 · 1 comment
Closed

file_handle.close() is never called -- and it causes a bug!! #607

stxlvt opened this issue Nov 26, 2015 · 1 comment
Labels
bug This issue/PR relates to a bug.

Comments

@stxlvt
Copy link

stxlvt commented Nov 26, 2015

In https://github.com/audreyr/cookiecutter/blob/master/cookiecutter/generate.py#L90, file_handle.close() is never called, and there's no need for it to remain open.

This is the first time in over 10 years of python programming that I've run into an actual issue with file handles left open, so I felt that the use of two exclamation points in the subject was warranted. I'm removing a temporary template after an unrelated error, and...

  File "D:\anaconda32\lib\shutil.py", line 250, in rmtree
    os.remove(fullname)
WindowsError: [Error 32] The process cannot access the file because it is being
used by another process: '.\\tmpp2duu1\\cookiecutter.json'

This change in generate.py:90 helps python not stumble on this particular issue:

try:
    with open(context_file) as file_handle:
        obj = json.load(file_handle, object_pairs_hook=OrderedDict)
except ValueError as e:
    # ...
@hackebrot
Copy link
Member

Thank you @stxlvt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants