matplotlib/matplotlib — pull request #3536 by anntzer (2014-09-18 08:02:52+00:00)
Title: Use tempfile.mkdtemp for animation.FileMovieWriter.

Currently, `animation.FileMovieWriter` (e.g. `FFMpegFileWriter`)
creates temporaries in the current folder, without even checking
whether the file existed before. This is obviously risky (e.g., create
a file named `_tmp0000000.png` in the current folder before running
`moviewriter.py` from the docs examples and it will be overwritten.
Moveover, temporaries are not cleaned up if an exception is raised
(e.g., KeyboardInterrupt).

This is relatively easy to fix using `tempfile.mkdtemp`, although I
had to modify `finish` so that it doesn't call `cleanup` by itself
(obviously, this can be fixed by keeping a `cleaned_up` attribute
but it feels like a minor API change is preferable; moreover the
context-manager API stays the same).

Only basic, manual testing done.