Avoid filesystem writes when there are no bytes to write.
See original GitHub issueDescription
https://github.com/astropy/astropy/blob/main/astropy/io/fits/hdu/table.py#L939 which pads FITS binary tables that variable-length columns out to the necessary multiple of 2880, can be triggered even when data._gap == 0
. That is, fileobj.write(b'')
is not a no-op.
This padding may also be needed if a table or image is not itself an exact multiple of 2880 bytes, so it may be possible to trigger this even when there are no variable-length columns.
Expected behavior
Don’t trigger a filesystem write if there is nothing to write:
if data._gap > 0:
fileobj.write((data._gap * '\0').encode('ascii'))
Actual behavior
The Lustre filesystem has a known issue that is triggered when zero-length writes are attempted. This bug report is an attempt to provide a workaround, and in general raise consciousness of corner cases that can happen in certain filesystems.
EDIT: Permalink to the code below
Issue Analytics
- State:
- Created 2 years ago
- Comments:19 (19 by maintainers)
Top GitHub Comments
In principle the fix is petty simple:
The trick will be to write a unit test that exercises this. That’s been holding me up.
The Python docs say the standard
open
is in fact an alias toio.open
; anywayfits.open
also works with filehandles likeso if you replace
fh
with a handle created by such a custom opener, you should be done – ideally 😉