-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
weldx.asdf.util.read_buffer
relies on reading from a 'closed' buffer
#873
Comments
thank you for reporting this, I like your suggestion using the context manager. As you mentioned in your comments, the function is mostly used in our testing pipelines. I will try to look into the best way to prevent running into this for now. |
Thanks! I opened a PR with updates that should be compatible with a fix to asdf-format/asdf#1539 I looked a bit at the ASDF issue yesterday and it affects more than just |
* add read_buffer_context and write_read_buffer_context closes #873 * update changelog * update dummy test * add read_buffer_context and write_read_buffer_context closes #873 * update changelog * update dummy test * removed internal keyword dummy_inline_arrays --------- Co-authored-by: Çağtay Fabry <43667554+CagtayFabry@users.noreply.github.com> Co-authored-by: Martin K. Scherer <m.scherer@fu-berlin.de>
ASDF was allowing lazily loaded arrays to be read from an AsdfFile created by reading an
io.BytesIO
instance. This results in unexpected changes to the position of the read/write pointer within the stream.See asdf-format/asdf#1539 for the relevant ASDF issue.
It appears that weldx relies upon this behavior for any tests using
weldx.asdf.util.read_buffer
. The relevant code is as follows:weldx/weldx/asdf/util.py
Lines 171 to 189 in c2ee9b1
Note that
data
is returned outside of theasdf.open
context (which closes the underlying 'file' when the context exits). Aslazy_load=True
was not provided toasdf.open
the arrays within the AsdfFile are 'lazy loaded' (their data is not read from the file until the array is sliced or in other ways accessed). One example of a test that will fail when the above issue is fixed in ASDF istest_shape_validator
:weldx/weldx/tests/asdf_tests/test_asdf_validators.py
Lines 150 to 155 in c2ee9b1
Here
result
contains references to 'lazy loaded' arrays that hold references to the now closed file. The call tocompare_nested
will then attempt to load the arrays which when the issue is fixed in ASDF will result in an error.I see one usage of
read_buffer
outside of tests inweldx.asdf.cli.welding_schema
:weldx/weldx/asdf/cli/welding_schema.py
Lines 303 to 306 in c2ee9b1
However this does not appear to use the result of
write_read_buffer
.I would imagine that one of two solutions might work:
lazy_load=True
withasdf.open
to force loading of all arrays when the file is openedread_buffer
(andwrite_read_buffer
) to context managers to allow the file to stay open while the results are usedThe first option seems like the easiest but will result in all arrays being loaded into memory (which might not be necessary for every call to
read_buffer
).The text was updated successfully, but these errors were encountered: