PeachPy icon indicating copy to clipboard operation
PeachPy copied to clipboard

writer.py: postpone creating the output file

Open bawr opened this issue 9 years ago • 4 comments

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.

bawr avatar Jun 02 '16 15:06 bawr

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.

Maratyszcza avatar Jun 02 '16 16:06 Maratyszcza

Right, do you foresee a problem with closing the file early, in the exception branch?

That was basically the other quick fix I considered.

bawr avatar Jun 02 '16 16:06 bawr

Closing + unlinking? Or just closing?

Maratyszcza avatar Jun 02 '16 16:06 Maratyszcza

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. ;)

bawr avatar Jun 03 '16 07:06 bawr