Use 'with file' more.

This helps to minimize ResourceWarning triggered by ^C with python3.