add handling for multiple read/write permissions issues#130
add handling for multiple read/write permissions issues#130mdeshotel wants to merge 10 commits intodevelopmentfrom
Conversation
mxkpp
left a comment
There was a problem hiding this comment.
Most comments apply throughout.
Generally also, please write a shared function that can be used multiple times.
| ) | ||
| sleep(1) | ||
| c += 1 | ||
| if c == 10: |
There was a problem hiding this comment.
Since the goal is to raise an error if the break is not reached, you can use else: instead of if c == 10:.
| ds.to_netcdf(self.nc_path, "w") | ||
| break | ||
| except Exception as e: | ||
| warnings.warn( |
| c += 1 | ||
| if c == 10: | ||
| raise PermissionError( | ||
| f"Could write the netcdf cache file within the specified number of retries(10): {self.nc_path}" |
| try: | ||
| ds.to_netcdf(self.nc_path, "w") | ||
| break | ||
| except Exception as e: |
There was a problem hiding this comment.
Is there a more specific exception type to catch?
There was a problem hiding this comment.
We have experienced a number of errors in the bug tickets. I'm catching any error and logging it so that if/when an error is reached we have a better starting point for figuring out what went wrong.
There was a problem hiding this comment.
Ok, fine if all exception types should be caught but the message should be less precise then.
| break | ||
| except Exception as e: | ||
| warnings.warn( | ||
| f"There appears to be a lock on the netcdf cache file while writing. Sleeping 1 second and trying again ({c}). | Error: {e}" |
There was a problem hiding this comment.
On the last time that it reaches this, it does not actually try again
| with xr.open_dataset(self.nc_path, engine="netcdf4") as ds: | ||
| dataset = ds.load() | ||
| return dataset |
There was a problem hiding this comment.
Why is this returning ds.load() result now? Existing behavior was to return xr.open_dataset() result.
There was a problem hiding this comment.
I switched to a context manager for opening/closing the file. the ds.load() loads the data all at once into memory prior to exiting the context manager and closing the file.
This PR attempts to resolve a permissions issue with the cache files for historical simulations. For writing cache files the following is implemented:
For read conflicts (if they exists), the following logic is applied:
Additions
Removals
Changes
Testing
Screenshots
Notes
Todos
Checklist
Testing checklist
Target Environment support