Supervisor/supervisor — pull request #397 by msabramo (2014-03-03 21:05:42+00:00)
Title: make an assert_no_leaks decorator that does stuff with lsof

I'm not happy with how many lines I had to touch to do this, so this might not be ready for merge, but maybe this will inspire some ideas about how to do it better.

You saw that I had a bunch of PRs to the `py3k` branch to fix various leaks that cause `ResourceWarning` messages in Python 3. I was wondering if we also have these leaks on master. Unfortunately, Python 2 doesn't emit the `ResourceWarning` so I wanted to have some kind of check for leaks. I messed around with a nose plugin called "drippy" but couldn't get it to detect these leaks. I eventually found this way to detect temp file leaks using `lsof`.

I implemented it as a context manager. I would've preferred to use a decorator so we could just slap it on each function and not have to indent a bunch of lines of code, but alas the decorator wouldn't detect the problems. It seems that somehow the resources get closed before the decorator can detect them. Maybe I did something wrong though. Or maybe this could be made into a nose plugin. I thought I'd post what I have before getting too deep into this, in case you already know of some tool that does this or something.

Anyway, this shows that there are indeed leaks on the `master` branch too:

```
❯ .tox/py26/bin/nosetests supervisor.tests.test_http
nose.plugins.cover: ERROR: Coverage not available: unable to import coverage module
..................*** assert_no_leaks: leaks found in test_handle_request:
python2.6 45174 marca 3u REG 1,2 0 23404501 /private/var/folders/gw/w0clrs515zx9x_55zgtpv4mm0000gp/T/tmpRojLaZ
python2.6 45174 marca 4r REG 1,2 0 23404501 /private/var/folders/gw/w0clrs515zx9x_55zgtpv4mm0000gp/T/tmpRojLaZ
....*** assert_no_leaks: leaks found in test_handle_request:
python2.6 45174 marca 3u REG 1,2 0 23404503 /private/var/folders/gw/w0clrs515zx9x_55zgtpv4mm0000gp/T/tmpRZ2R5b
python2.6 45174 marca 5r REG 1,2 0 23404503 /private/var/folders/gw/w0clrs515zx9x_55zgtpv4mm0000gp/T/tmpRZ2R5b
........*** assert_no_leaks: leaks found in test_handle_more:
python2.6 45174 marca 6r REG 1,2 0 23404504 /private/var/folders/gw/w0clrs515zx9x_55zgtpv4mm0000gp/T/tmpTbXedk
python2.6 45174 marca 3u REG 1,2 0 23404504 /private/var/folders/gw/w0clrs515zx9x_55zgtpv4mm0000gp/T/tmpTbXedk
....
----------------------------------------------------------------------
Ran 34 tests in 1.684s

OK
```