What was happening on Windows is that that the temporary directory was being garbage collected before the open file handle temporary file inside of it. This was probably also handling on *ix, but it was harmless.
On Windows, the temporary directory object needs to live a bit longer than the local tempfile, which needs to live a bit longer than than the SQL Alchemy connection to the tempfile.
So I use an ExitStack to inject cleanup code which is run before the connection is closed and the file handle is released.
All of this is triggered by the garbage collector letting go of the iterator when the recipe is finishing up.
It might be better to do a deterministic, explicit, top-down cleanup, but that should probably be a different PR.
Fixes #901
What was happening on Windows is that that the temporary directory was being garbage collected before the open file handle temporary file inside of it. This was probably also handling on *ix, but it was harmless.
On Windows, the temporary directory object needs to live a bit longer than the local tempfile, which needs to live a bit longer than than the SQL Alchemy connection to the tempfile.
So I use an ExitStack to inject cleanup code which is run before the connection is closed and the file handle is released.
All of this is triggered by the garbage collector letting go of the iterator when the recipe is finishing up.
It might be better to do a deterministic, explicit, top-down cleanup, but that should probably be a different PR.