GuppyFile.get_data() raises StopIteration
daniestevez opened this issue · comments
I'm running Blimpy 2.0.11 under Python 3.7.6 and I have found that GuppyFile.get_data()
raises StopIteration
, which Python 3.7 will transform into a RuntimeError
. This will terminate the execution of the script unless the RuntimeError
is caught. This has to do with PEP 479, which was introduced in Python 3.7.
This can be replicated using the example code
from blimpy import GuppiRaw
gr = GuppiRaw('/path/to/guppirawfile.raw')
for header, data_x, data_y in gr.get_data():
# process data
Such an example will give the following traceback:
File depleted
Traceback (most recent call last):
File "/opt/conda/lib/python3.7/site-packages/blimpy/guppi.py", line 209, in get_data
yield gr.generator_read_next_data_block_int8()
File "/opt/conda/lib/python3.7/site-packages/blimpy/guppi.py", line 239, in generator_read_next_data_block_int8
header, data_idx = self.read_header()
File "/opt/conda/lib/python3.7/site-packages/blimpy/guppi.py", line 118, in read_header
raise EndOfFileError("End Of Data File")
blimpy.guppi.EndOfFileError: End Of Data File
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/conda/lib/python3.7/site-packages/blimpy/guppi.py", line 212, in get_data
raise StopIteration
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/destevez/test.py", line 4, in <module>
for header, data_x, data_y in gr.get_data():
RuntimeError: generator raised StopIteration
In PEP 479 it is stated that
Finally, the proposal also clears up the confusion about how to terminate a generator: the proper way is return, not raise StopIteration.
Therefore, I think that using return
instead of StopIteration
in GuppyFile.get_data()
would fix this problem, but I'm not 100% how this interacts with Python 2.7. If you think this is a good solution, I can submit a PR with the change.
@daniestevez
It's amazing that nobody has reported this before!
Fixed as you suggested + a little cleanup in guppi.py
and rawhdr.py
.
Thanks! This can be closed whenever you want.
@daniestevez
Note that you can close issues that you have opened once you are satisfied with a resolution.