Fixes for ResourceWarning errors with Python 3.