djsutho / django-debug-toolbar-request-history

BSD 3-Clause "New" or "Revised" License
131 stars 23 forks source link

Viewing request history is "leaking" a file handle (minor) #13

Closed jlaunonen closed 7 years ago

jlaunonen commented 7 years ago

Causes following warning to be issued (on v0.0.4 with python -Wd enabled):

ddt_request_history/panels/request_history.py:144: ResourceWarning: unclosed file <_io.TextIOWrapper name='ddt_request_history/panels/request_history.html' mode='r' encoding='UTF-8'> t = Template(open(template_path).read())

The culprit at ddt_request_history/panels/request_history.py#L177 should probably read something like

with open(template_path) as f:
    t = Template(f.read())
djsutho commented 7 years ago

I've added a fix for this but was unable to replicate the error with running via python -Wd (I assume you run some with python -Wd ./manage.py runserver) so I would appreciate it if you could test this for me. Thanks for picking this up.

jlaunonen commented 7 years ago

Hi, yes, 6baf17cfa62708f5514674a4d87893f4944e0fb2 fixes this issue. Thanks! And yes, that's how I ran it, though I seem to have been a bit ambiguous: that's python 3.5+. The ResourceWarning -class was added around py 3.2 and thus this is not shown on earlier interpreter versions.