Description:
I am experiencing a segmentation fault or ECCODES runtime errors when using both eccodes (Python bindings) and pygrib in the same script. The crash/error occurs depending on the order of operations.
Steps to reproduce:
Scenario 1 (segmentation fault):
from eccodes import *
import pygrib
f = open("1.grib", 'rb')
gid = codes_grib_new_from_file(f)
codes_release(gid)
f.close()
grbs = pygrib.open("2.grib") # Segmentation fault here
Scenario 2 (ECCODES runtime error):
from eccodes import *
import pygrib
grbs = pygrib.open("2.grib") # This succeeds
f = open("1.grib", 'rb')
gid = codes_grib_new_from_file(f) # Error occurs here
Error output for Scenario 2:
ECCODES ERROR : STL exception: unordered_map::at
ECCODES ERROR : Runtime error
ECCODES ERROR : grib_handle_new_from_file_no_multi: Cannot create handle
Expected behavior:
Both libraries should be usable in the same script without conflicts, regardless of the order of file operations.
Actual behavior:
-
If eccodes is used first, a segmentation fault occurs when later calling pygrib.open().
-
If pygrib is used first, eccodes operations fail with an ECCODES internal error (unordered_map::at).
Environment:
-
eccodes Python bindings version: 2.47.0
-
eccodeslib version: 2.46.2.19
-
pygrib version: 2.1.8
-
Operating system: Ubuntu 24.04
-
Python version: 3.12/3.13
Additional context:
Both packages are wrappers around the ECCODES C library. The errors suggest that the two bindings are not isolated – they interfere with each other's internal state (e.g., global contexts, error queues, or C++ static objects). This makes it impossible to use both packages together in the same Python process.
Possible workaround:
Use only one of the libraries in a given Python session. Alternatively, one might try to load them in separate subprocesses, but that is not a real solution for interactive workflows.
Please investigate whether the Python bindings for ECCODES can be made safe for co-existence with pygrib. Thank you!
Description:
I am experiencing a segmentation fault or ECCODES runtime errors when using both eccodes (Python bindings) and pygrib in the same script. The crash/error occurs depending on the order of operations.
Steps to reproduce:
Scenario 1 (segmentation fault):
Scenario 2 (ECCODES runtime error):
Error output for Scenario 2:
Expected behavior:
Both libraries should be usable in the same script without conflicts, regardless of the order of file operations.
Actual behavior:
If eccodes is used first, a segmentation fault occurs when later calling pygrib.open().
If pygrib is used first, eccodes operations fail with an ECCODES internal error (unordered_map::at).
Environment:
eccodes Python bindings version: 2.47.0
eccodeslib version: 2.46.2.19
pygrib version: 2.1.8
Operating system: Ubuntu 24.04
Python version: 3.12/3.13
Additional context:
Both packages are wrappers around the ECCODES C library. The errors suggest that the two bindings are not isolated – they interfere with each other's internal state (e.g., global contexts, error queues, or C++ static objects). This makes it impossible to use both packages together in the same Python process.
Possible workaround:
Use only one of the libraries in a given Python session. Alternatively, one might try to load them in separate subprocesses, but that is not a real solution for interactive workflows.
Please investigate whether the Python bindings for ECCODES can be made safe for co-existence with pygrib. Thank you!