LSSTDESC / rail_base

Base classes for RAIL
MIT License
0 stars 1 forks source link

Output files created by parallelized or chunked stages are not properly closed #92

Closed drewoldag closed 3 months ago

drewoldag commented 4 months ago

This is a minor bug, but odd none the less. I noted that files (specifically hdf5 format) that were created with _do_chunk_output (or equivalent) can be opened, read, and closed programmatically with h5py, but when I used a GUI plug in for my IDE, the files were considered invalid unless I opened then, importantly, closed them with h5py.

Additionally, when the files were written in a single shot, without ever producing a temporary, "inprogress_.hdf5" file, they were correctly formatted, and presumably closed by some mechanism inside RAIL.

After some investigation, I found RailStage._finalize_tag contained conditional logic that would call handle.write() (which will close a file) only if the file handle didn't already exist. Removing the conditional check for file existence, but keeping handle.write() seems to fix the problem and luckily doesn't obviously introduce collateral problems.

The unit tests all pass, and my notebooks run, but I don't have high confidence that there are not other problems introduced by the change.

Before submitting Please check the following: