kiyo-masui / bitshuffle

Filter for improving compression of typed binary data.
Other
219 stars 76 forks source link

Install h5py without wheel test #107

Closed james-s-willis closed 3 years ago

james-s-willis commented 3 years ago

@t20100, since your change to dynamically load libhdf5 (#81). We've noticed a seg fault in bitshuffle when importing:

from bitshuffle import h5
Fatal Python error: Segmentation fault

Current thread 0x00007f42266f1740 (most recent call first):
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 929 in exec_module
  File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 971 in _find_and_load
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1023 in _handle_fromlist
  File "/home/runner/work/bitshuffle/bitshuffle/tests/test_h5filter.py", line 11 in <module>
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/assertion/rewrite.py", line 170 in exec_module
  File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 971 in _find_and_load
  File "<frozen importlib._bootstrap>", line 994 in _gcd_import
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/importlib/__init__.py", line 126 in import_module
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/pathlib.py", line 524 in import_path
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/python.py", line 578 in _importtestmodule
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/python.py", line 500 in _getobj
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/python.py", line 291 in obj
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/python.py", line 516 in _inject_setup_module_fixture
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/python.py", line 503 in collect
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/runner.py", line 341 in <lambda>
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/runner.py", line 311 in from_call
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/runner.py", line 341 in pytest_make_collect_report
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/runner.py", line 458 in collect_one_node
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/main.py", line 808 in genitems
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/main.py", line 634 in perform_collect
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/main.py", line 333 in pytest_collection
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/main.py", line 322 in _main
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/main.py", line 269 in wrap_session
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/main.py", line 316 in pytest_cmdline_main
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/config/__init__.py", line 163 in main
  File "/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/_pytest/config/__init__.py", line 185 in console_main
  File "/opt/hostedtoolcache/Python/3.6.14/x64/bin/pytest", line 8 in <module>
/home/runner/work/_temp/67764068-ecd0-41de-aecd-771d2c884ae7.sh: line 1:  2681 Segmentation fault      (core dumped) pytest .

But this only occurs when installing h5py with: pip install --no-binary=h5py h5py. Have you seen this kind of error before?

james-s-willis commented 3 years ago

It seg faults when trying to load the following symbols in hdf5_dl.c:

        /*Variables*/
        H5E_CANTREGISTER_g = *((hid_t *)dlsym(handle, "H5E_CANTREGISTER_g"));
        H5E_CALLBACK_g = *((hid_t *)dlsym(handle, "H5E_CALLBACK_g"));
        H5E_PLINE_g = *((hid_t *)dlsym(handle, "H5E_PLINE_g"));
        H5E_ERR_CLS_g = *((hid_t *)dlsym(handle, "H5E_ERR_CLS_g"));                                                                                                                                                
t20100 commented 3 years ago

I tried to reproduce locally following similar steps as in CI:

We never got such issue reported to hdf5plugin and it worked in both cases.

t20100 commented 3 years ago

It looks to be related to calling init_filter from cython code.

I made it work by commenting the calls to init_filter and register_h5_filter in h5.pyx and running:

from bitshuffle import h5
import h5py, ctypes

lib = ctypes.CDLL(h5.__file__)
lib.init_filter.argtypes = [ctypes.c_char_p]
lib.init_filter.restype = ctypes.c_int
lib.init_filter(bytes(h5py.h5z.__file__, encoding='utf-8'))

h5.register_h5_filter()
james-s-willis commented 3 years ago

Thanks for looking into this. I found that H5E_CANTREGISTER_g, H5E_CALLBACK_g, H5E_PLINE_g, H5E_ERR_CLS_g symbols are not included in h5py.h5d when h5py is installed with --no-binary=h5py. If you use h5py.h5z (like in your fix) to initialise the filter it works fine.

t20100 commented 3 years ago

Good! I actually use h5z in hdf5plugin, but I didn't expected that would make a difference to use another... maybe it depends on the way h5py links to libhdf5.