1. Ned Batchelder
  2. coverage.py
  3. Issues
Issue #104 resolved

Explicitly close files

Brett Cannon
created an issue

There are three places in coverage.py where a file is simply opened and read from in a single line, e.g., {{{open(file_path)read()}}}. While technically valid, it does rely somewhat on CPython semantics of refcounting; other VMs might not close the open file quickly. It also triggers ResourceWarnings in Python 3.2 when run under development settings.

A patch is attached which adds try/finally blocks to explicitly close files.

Comments (2)

  1. Ned Batchelder repo owner

    Brett, thanks, I should have known this, having made these very same changes to Cog when porting to Jython. The patch looks great, but I won't get to applying it for a few days...

  2. Log in to comment