-
Notifications
You must be signed in to change notification settings - Fork 262
Fix for issue 362: nibabel fails to stream gzipped files > 4GB (uncompressed) in Python 3.5 #383
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
Conversation
@@ -17,11 +17,36 @@ | |||
GZIP_MAX_READ_CHUNK = 100 * 1024 * 1024 # 100Mb | |||
|
|||
|
|||
class BufferedGzipFile(gzip.GzipFile): | |||
"""GzipFile capable to readinto buffer >= 2**32 bytes.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"able to" rather than "capable to"
I haven't been following this PR, but I'm blocking 2.0.2 on this. Let me know if I shouldn't be. |
@effigies This "fix" didn't actually work. I will submit a temporary workaround we discussed previously, this afternoon. Job interview this morning! :) |
I will work on an update... |
OK, fixed this by using If someone could pull this branch and run the Python 3.5 test, would be great. Will have to set Last question: where to document the use of |
class BufferedGzipFile(gzip.GzipFile): | ||
"""GzipFile able to readinto buffer >= 2**32 bytes.""" | ||
def __init__(self, fileish, mode='rb', compresslevel=9, buffer_size=2**32-1): | ||
super(BufferedGzipFile, self).__init__(fileish, mode=mode, compresslevel=compresslevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like gzip.GzipFile
is not a new-style class in 2.6.
I think this should work:
gzip.GzipFile.__init__(self, fileish, mode=mode, compresslevel=compresslevel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Sorry to ask - but would you consider adding a small "Running the tests" section to |
Great; exactly what I was looking for. Will do. |
@matthew-brett a bit puzzled about pushing documentation to |
I tested this locally on my machine, it worked well. I will temporarily push a change to |
return super(BufferedGzipFile, self).readinto(buf) | ||
|
||
# This works around a known issue in Python 3.5. | ||
# See https://bugs.python.org/issue25626""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No """
needed.
… returned data read/copy fails).
ok, updated code again per comments. |
def decorator(func): | ||
return skipif(test_str not in EXTRA_SET, | ||
"Skip {0} tests.".format(test_str))(func) | ||
return decorator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm going to be annoying and insist on removing the decorator
function. What you have is:
def f(x):
return g(x)
return f
When you could just have return g
. Just use:
def runif_extra_has(test_str):
return skipif(test_str not in EXTRA_SET, "Skip {0} tests.".format(test_str))
Thanks for your patience. LGTM. |
Squashed for 2.0.2 release. See nipygh-383 for full history. BF: Use buffered gzip read in Py3.5.0, specifically TST: Add high-memory usage test for large nifti1 files Conflicts: nibabel/testing/__init__.py
Squashed for 2.0.2 release. See nipygh-383 for full history. BF: Use buffered gzip read in Py3.5.0, specifically TST: Add high-memory usage test for large nifti1 files Conflicts: nibabel/testing/__init__.py
Squashed for 2.0.2 release. See nipygh-383 for full history. BF: Use buffered gzip read in Py3.5.0, specifically TST: Add high-memory usage test for large nifti1 files Conflicts: nibabel/testing/__init__.py
img.to_filename('test.nii.gz') | ||
del img | ||
data = load('test.nii.gz').get_data() | ||
# Check that te data are all ones |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type 'te'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow' that's meta. I meant "typo 'te'"
I can confirm that HCP is working again on Python 3.5. Cheers ! |
👍 @matthew-brett still looking for some details on best place for docs; I think it's the last thing to do. |
Squashed for 2.0.2 release. See nipygh-383 for full history. BF: Use buffered gzip read in Py3.5.0, specifically TST: Add high-memory usage test for large nifti1 files Conflicts: nibabel/testing/__init__.py
Nifti1Pair, Nifti1Extension, Nifti1Extensions, | ||
data_type_codes, extension_codes, | ||
slice_order_codes) | ||
from nibabel.openers import ImageOpener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import.
Ben - sorry - are you asking me where to put the docs? |
Yes, I'm not sure where to add the documentation about the new test env variable. "Installation" felt odd to me, as it seems like a developer / release issue, so I wanted to double-check. In "installation", can you give me an idea how you envisioned it fitting in? |
How about a little section on 'testing' in the installation docs, pointing to a document |
@matthew-brett Not sure if this is what you had in mind... |
Squashed for 2.0.2 release. See nipygh-383 for full history. BF: Use buffered gzip read in Py3.5.0, specifically TST: Add high-memory usage test for large nifti1 files Conflicts: nibabel/testing/__init__.py
I was thinking of something like 'to run tests, run Then advanced testing would be using the git submodules, as in:
and the slow tests stuff. |
Looks good - maybe add that |
Done. I think we're ready to go! |
Great - thanks again for wading through. |
MRG: Fix for issue 362: Python 3.5 fails reading large gzipped files This not a nibabel bug, but works around a Python bug (https://bugs.python.org/issue25626). The workaround is: we wrap gzip.GzipFile with buffering, so that files > 4GB require multiple calls to GzipFile.readinto. I've also added test functionality: if NIPY_EXTRA_TESTS contains 'slow', slowly running tests can be run. I've used this to include a test for creation of a large file.
Squashed for 2.0.2 release. See nipygh-383 for full history. BF: Use buffered gzip read in Py3.5.0, specifically TST: Add high-memory usage test for large nifti1 files Conflicts: nibabel/testing/__init__.py
Running the slow tests on a big Mac buildbot : http://nipy.bic.berkeley.edu/builders/nibabel-py2.7-osx-10.10/builds/27/steps/shell_5/logs/stdio |
MRG: Fix for issue 362: Python 3.5 fails reading large gzipped files This not a nibabel bug, but works around a Python bug (https://bugs.python.org/issue25626). The workaround is: we wrap gzip.GzipFile with buffering, so that files > 4GB require multiple calls to GzipFile.readinto. I've also added test functionality: if NIPY_EXTRA_TESTS contains 'slow', slowly running tests can be run. I've used this to include a test for creation of a large file.
This not a
nibabel
bug, but works around a Python bug (https://bugs.python.org/issue25626).The workaround is: we wrap
gzip.GzipFile
with buffering, so that files > 4GB require multiple calls toGzipFile.readinto
.I've also added test functionality: if
NIPY_EXTRA_TESTS
contains'slow'
, slowly running tests can be run. I've used this to include a test for creation of a large file.