ecmwf / eccodes-python

Python interface to the ecCodes GRIB/BUFR decoder/encoder
Apache License 2.0
115 stars 33 forks source link

Segfault when closing GribFile if messages are closed manually #28

Closed matthewlloyd closed 4 years ago

matthewlloyd commented 4 years ago

This code works fine:

with eccodes.GribFile('test.grib2') as gf:
    while True:
        try:
            message = gf.next()
        except StopIteration:
            break

On the other hand, this code, which manually closes each message to save memory, segfaults :

with eccodes.GribFile('test.grib2') as gf:
    while True:
        try:
            message = gf.next()
        except StopIteration:
            break
        message.close()

Here's the backtrace:

Current thread 0x00007efd4ed45740 (most recent call first):
  File "/usr/local/lib/python3.6/site-packages/gribapi/gribapi.py", line 474 in grib_release
  File "/usr/local/lib/python3.6/site-packages/eccodes/high_level/codesmessage.py", line 165 in __exit__
  File "/usr/local/lib/python3.6/site-packages/eccodes/high_level/gribmessage.py", line 61 in __exit__
  File "/usr/local/lib/python3.6/site-packages/eccodes/high_level/codesmessage.py", line 172 in close
  File "/usr/local/lib/python3.6/site-packages/eccodes/high_level/codesfile.py", line 52 in __exit__
  File "<ipython-input-5-abd830c3b0f5>", line 7 in <module>
  File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3296 in run_code
  File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3214 in run_ast_nodes
  File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3049 in run_cell_async
  File "/usr/local/lib/python3.6/site-packages/IPython/core/async_helpers.py", line 67 in _pseudo_sync_runner
  File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2874 in _run_cell
  File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2848 in run_cell
  File "/usr/local/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 489 in interact
  File "/usr/local/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 498 in mainloop
  File "/usr/local/lib/python3.6/site-packages/IPython/terminal/ipapp.py", line 356 in start
  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 658 in launch_instance
  File "/usr/local/lib/python3.6/site-packages/IPython/__init__.py", line 125 in start_ipython
  File "/usr/local/bin/ipython3", line 10 in <module>
Segmentation fault

According to the class-level doc for CodesMessage, # If desired, messages can be closed manually or used in with, so this should work.

eccodes 2.17.0

shahramn commented 4 years ago

Thank you Matthew.

It would be best to send your issues to our Software Support team. Then they will create appropriate tickets (we use JIRA from Atlassian) to be handed to the Development Team. So can you please kindly write to:

Software.Support@ecmwf.int

Many thanks

matthewlloyd commented 4 years ago

Done, thanks!