fix: close temp file before trying to move/delete#449
Merged
danielolsen merged 1 commit intodevelopfrom Apr 13, 2021
Merged
Conversation
rouille
approved these changes
Apr 13, 2021
Collaborator
rouille
left a comment
There was a problem hiding this comment.
I don't see anything wrong with that
jenhagg
approved these changes
Apr 13, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fix the PermissionsErrors we had been getting on Windows.
What the code is doing
After writing to the tempfile, we tell the os to close the file before we try to do anything with it (e.g. move, delete). I got this from this stackoverflow post: https://stackoverflow.com/questions/34716996/cant-remove-a-file-which-created-by-tempfile-mkstemp-on-windows
Testing
Tests on Windows now pass, and I've successfully tested that this can create/prepare/launch a scenario on the server (previously had been failing so I fell back to the 'v0.4.1' branch).
Previously all test_execute_csv and test_scenario_csv tests failed with an error like:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\DanielOlsen\\ScenarioData\\tmpmvu_jnyl'Time estimate
5-15 minutes, depending on how far you want to go down the low level file API rabbit hole.