3 ms·I suppose adding f.close() right after the flush might help.by tyingq 7y agoI suppose adding f.close() right after the flush might help.nneonneo 7y agoThe file is in a with block - it should be automatically closed at the end of the block.tyingq 7y agoYes, but if it fixes the issue then there's something off with NamedTemporaryFile and its __exit__. You mentioned the file descriptor was being closed by a GC run, right?