writer.py: postpone creating the output file
Windows can't unlink a file while it is still open, and raises an exception. Additionally, self.output_file isn't accessed anywhere else, by any methods. As such, creation should happen after we make sure that there are no bugs.
The motivation for creating a file early is to fail fast if the file can't be created (e.g. parent directory doesn't exist or insufficient access rights). I would accept a fix for the unlinking-on-Windows problem, but without postponing file creation.
Right, do you foresee a problem with closing the file early, in the exception branch?
That was basically the other quick fix I considered.
Closing + unlinking? Or just closing?
Closing the file before we attempt to unlink it -- if there is an error.
Code talks better than descriptions, so I guess later today I'll just revert this, make that tiny change, and you can take it from there. No point in spending more time than that, when the fix I have in mind is literally on the order of four lines. ;)