Automated PEP8 fixes
Better Python 2 / 3 compatibility

This fixes the breaking changes for Python 2 that were made in the
last attempt and improves Python 3 compatibility a bit more.

Python 3 supports the new `file` argument to the `print` function
that allows you to specify where to print to.  In the code, this
was being used to print to stderr.  Unfortunately Python 2 does not
yet support this, so we are now using `sys.stderr.write` instead.

Python 2's `Queue` module was renamed to `queue` in Python 3.  We
should be importing them both to ensure that the code runs on both
versions.  By default, we are assuming that Python 3 will be used
and are using it as the first import before falling back to the old
name.

`threading._sleep` was a private method and was removed in Python 3.
It has been replaced by `time.sleep` for now, as that is both public
and consistent across versions.

When determining chunk sizes and the number of chunks, there was a
possibility of floating values being passed in or calculated.  To
ensure that the generated range does not throw an exception, we are
manually casting these to integers.

The iterator was previously changed so `next` became `__next__`,
which was the Python 3 method for the `next` function.  This adds
Python 2 compatibility alongside of these changes.