Could you use tempfile.NamedTemporaryFile(delete=False) instead?