Avoid races in test_member_freeze.
Fix most ResourceWarnings under Python 3.