Skip to content

Conversation

@KristijanFaust-OET
Copy link
Contributor

Closes # (if applicable).

Changes proposed in this Pull Request

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@FabianHofmann FabianHofmann merged commit 5c2deec into PyPSA:master Sep 11, 2025
22 checks passed
Comment on lines +498 to +503
model_dump_path = None
with tempfile.NamedTemporaryFile(prefix="linopy-", suffix=".nc") as fn:
model.to_netcdf(fn.name)
input_file_name = self._upload_file_to_gcp(fn.name)
model_dump_path = fn.name

model.to_netcdf(model_dump_path)
input_file_name = self._upload_file_to_gcp(fn.name)
Copy link
Member

@coroa coroa Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how to fix the permission problem. You loose that way the automatic cleanup and introduce a race condition.

The permission problem is due to tempfile.NamedTemporaryFile opening the file, which introduces a lock on windows. So you need to close it and then dump into it, instead, while keeping the context manager alive.

Suggested change
model_dump_path = None
with tempfile.NamedTemporaryFile(prefix="linopy-", suffix=".nc") as fn:
model.to_netcdf(fn.name)
input_file_name = self._upload_file_to_gcp(fn.name)
model_dump_path = fn.name
model.to_netcdf(model_dump_path)
input_file_name = self._upload_file_to_gcp(fn.name)
with tempfile.NamedTemporaryFile(prefix="linopy-", suffix=".nc") as fn:
fn.file.close()
model.to_netcdf(fn.name)
input_file_name = self._upload_file_to_gcp(fn.name)

@coroa coroa mentioned this pull request Sep 14, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants