conda-forge / gdcm-feedstock

A conda-smithy repository for gdcm.
BSD 3-Clause "New" or "Revised" License
1 stars 11 forks source link

PyThreadState_Get: no current thread #8

Open astrofrog opened 6 years ago

astrofrog commented 6 years ago

I've installed gdcm from conda-forge into my conda environment and if I import it I get a fatal Python error:

 In [1]: import faulthandler

In [2]: faulthandler.enable()

In [3]: import gdcm
Fatal Python error: PyThreadState_Get: no current thread

Fatal Python error: Aborted

Thread 0x000070000b1f5000 (most recent call first):
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/threading.py", line 295 in wait
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/threading.py", line 551 in wait
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/core/history.py", line 829 in run
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/core/history.py", line 58 in needs_sqlite
  File "<decorator-gen-24>", line 2 in run
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/threading.py", line 916 in _bootstrap_inner
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/threading.py", line 884 in _bootstrap

Current thread 0x00007fff8d5c2380 (most recent call first):
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 922 in create_module
  File "<frozen importlib._bootstrap>", line 571 in module_from_spec
  File "<frozen importlib._bootstrap>", line 658 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 "/Users/tom/miniconda3/envs/dev/lib/python3.6/importlib/__init__.py", line 126 in import_module
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/gdcmswig.py", line 17 in swig_import_helper
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/gdcmswig.py", line 20 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 678 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 "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/gdcm.py", line 62 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 678 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 "<ipython-input-3-7c9b65256043>", line 1 in <module>
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910 in run_code
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2850 in run_ast_nodes
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2728 in run_cell
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 471 in interact
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 480 in mainloop
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/terminal/ipapp.py", line 356 in start
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/traitlets/config/application.py", line 658 in launch_instance
  File "/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/IPython/__init__.py", line 125 in start_ipython
  File "/Users/tom/miniconda3/envs/dev/bin/ipython", line 11 in <module>
Abort trap: 6
astrofrog commented 6 years ago

This happens on MacOS X with the following environment:

ca-certificates           2018.03.07                    0  
certifi                   2018.4.16                py36_0  
gdcm                      2.8.4                    py36_0    conda-forge
libcxx                    4.0.1                h579ed51_0  
libcxxabi                 4.0.1                hebd6815_0  
libedit                   3.1                  hb4e282d_0  
libffi                    3.2.1                h475c297_4  
ncurses                   6.0                  hd04f020_2  
openssl                   1.0.2o               h26aff7b_0  
pip                       9.0.3                    py36_0    conda-forge
python                    3.6.5                hc167b69_1  
readline                  7.0                  hc1231fa_4  
setuptools                39.1.0                   py36_0    conda-forge
sqlite                    3.23.1               hf1716c9_0  
tk                        8.6.7                         0    conda-forge
wheel                     0.31.0                   py36_0    conda-forge
xz                        5.2.3                         0    conda-forge
zlib                      1.2.11               hf3cbc9b_2  

but not with:

ca-certificates           2018.4.16                     0    conda-forge
certifi                   2018.4.16                py36_0  
gdcm                      2.8.4                    py36_0    conda-forge
ncurses                   5.9                          10    conda-forge
openssl                   1.0.2o               h26aff7b_0  
pip                       9.0.3                    py36_0    conda-forge
python                    3.6.5                         1    conda-forge
readline                  7.0                           0    conda-forge
setuptools                39.1.0                   py36_0    conda-forge
sqlite                    3.20.1                        2    conda-forge
tk                        8.6.7                         0    conda-forge
wheel                     0.31.0                   py36_0    conda-forge
xz                        5.2.3                         0    conda-forge
zlib                      1.2.11               hf3cbc9b_2  
Korijn commented 6 years ago

I believe this is related to mixed linking of different python installations on the system. But I've never seen anyone resolve this one, unfortunately, short of system reinstallation

astrofrog commented 6 years ago

Yeah, this is frustrating - most users won't necessarily want to mess around with environments and if they just conda install -c conda-forge gdcm into their normal Anaconda environment things will break (e.g pydicom doesn't import).

astrofrog commented 6 years ago

@Korijn - it looks like this may be happening when loading libgdcmzlib:

In [1]: import gdcmswig
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/_gdcmswig.so
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmMEXD.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmMSFF.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmIOD.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libpython3.6m.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmDSED.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmCommon.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmDICT.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libsocketxx.1.2.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmjpeg8.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmjpeg12.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmjpeg16.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmopenjp2.7.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmcharls.1.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmuuid.2.8.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmexpat.2.0.dylib
dyld: loaded: /Users/tom/miniconda3/envs/dev/lib/libgdcmzlib.2.8.dylib
Fatal Python error: PyThreadState_Get: no current thread

Abort trap: 6

Is there a way to compile GDCM such that it does not install its own libraries that could be installed in other ways in conda?

astrofrog commented 6 years ago

I've investigated this some more, and this seems to happen if Python is installed from defaults rather than from conda-forge, and only Python 3.x (not 2.x). With a clean conda installation, the bug is easy to reproduce with:

conda create -n test python=3.5
source activate test
conda install -y -c conda-forge gdcm

Importing gdcm then results in the above issue.

Korijn commented 6 years ago

just a hint, this has to do with using a different python build at runtime than at buildtimr.

lianyi commented 6 years ago

got the same issue, anyone has a solution?