pytest segfaults but python -m pytest does not
See original GitHub issuetl;dr - read the title of this issue.
Related information
- Related issue: #2564
- Is triggered by: diana-hep/pyhf#385
- Related documentation: https://docs.pytest.org/en/latest/pythonpath.html#invoking-pytest-versus-python-m-pytest
This occurs as part of a travis-CI job. This is very hard to provide a MWE, so I will instead provide enough background information.
Environment
OS
travis@travis-job-2326826f-1987-469e-80ed-956889b8a731:~/build/diana-hep/pyhf$ uname -a
Linux travis-job-2326826f-1987-469e-80ed-956889b8a731 4.4.0-101-generic #124~14.04.1-Ubuntu SMP Fri Nov 10 19:05:36 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
pip list
Package Version Location
---------------------------------- ----------- ---------------------------------
absl-py 0.6.1
adal 1.2.0
alabaster 0.7.12
ansiwrap 0.8.3
asn1crypto 0.24.0
aspy.yaml 1.1.1
astor 0.7.1
atomicwrites 1.2.1
attrs 18.2.0
awkward 0.7.1
azure-common 1.1.16
azure-datalake-store 0.0.40
azure-nspkg 3.0.2
azure-storage-blob 1.4.0
azure-storage-common 1.4.0
azure-storage-nspkg 3.1.0
Babel 2.6.0
backports-abc 0.5
backports.functools-lru-cache 1.5
backports.shutil-get-terminal-size 1.0.0
backports.shutil-which 3.5.2
backports.weakref 1.0.post1
bleach 3.1.0
boto3 1.9.77
botocore 1.12.77
bumpversion 0.5.3
cachetools 3.0.0
certifi 2018.11.29
cffi 1.11.5
cfgv 1.4.0
chardet 3.0.4
Click 7.0
colorama 0.4.1
configparser 3.5.0
contextlib2 0.5.5
coverage 4.5.2
cryptography 2.4.2
cycler 0.10.0
decorator 4.3.0
defusedxml 0.5.0
docutils 0.14
entrypoints 0.3
enum34 1.1.6
funcsigs 1.0.2
functools32 3.2.3.post2
future 0.17.1
futures 3.2.0
gast 0.2.1.post0
gitdb2 2.0.5
GitPython 2.1.11
graphviz 0.10.1
grpcio 1.17.1
h5py 2.9.0
identify 1.1.8
idna 2.6
imagesize 1.1.0
iminuit 1.3.3
importlib-metadata 0.8
importlib-resources 1.0.2
ipaddress 1.0.22
ipykernel 4.10.0
ipython 5.8.0
ipython-genutils 0.2.0
ipywidgets 7.4.2
Jinja2 2.10
jmespath 0.9.3
jsonpatch 1.23
jsonpointer 2.0
jsonschema 3.0.0a4
jupyter 1.0.0
jupyter-client 5.2.4
jupyter-console 5.2.0
jupyter-core 4.4.0
Keras-Applications 1.0.6
Keras-Preprocessing 1.0.5
kiwisolver 1.0.1
latexcodec 1.0.5
m2r 0.2.1
Markdown 3.0.1
MarkupSafe 1.1.0
matplotlib 2.2.3
mistune 0.8.4
mock 2.0.0
more-itertools 5.0.0
mxnet 1.3.1
nbconvert 5.4.0
nbdime 1.0.4
nbformat 4.4.0
nbsphinx 0.4.1
nodeenv 1.3.3
nose 1.3.7
notebook 5.7.4
numpy 1.14.6
oset 0.1.3
packaging 18.0
pandas 0.23.4
pandocfilters 1.4.2
papermill 0.16.2
pathlib2 2.3.3
pbr 5.1.1
pexpect 4.6.0
pickleshare 0.7.5
pip 18.1
pkginfo 1.5.0.1
pluggy 0.8.1
pockets 0.7.2
pre-commit 1.14.1
prometheus-client 0.5.0
prompt-toolkit 1.0.15
protobuf 3.6.1
ptyprocess 0.6.0
py 1.7.0
py-cpuinfo 4.0.0
pybtex 0.22.0
pybtex-docutils 0.2.1
pycparser 2.19
pyflakes 2.0.0
pygal 2.4.0
pygaljs 1.0.1
Pygments 2.3.1
pyhf 0.0.15 /home/travis/build/diana-hep/pyhf
PyJWT 1.7.1
pyparsing 2.3.0
pyrsistent 0.14.9
pytest 3.10.1
pytest-benchmark 3.2.0
pytest-console-scripts 0.1.7
pytest-cov 2.6.1
pytest-mock 1.10.0
pytest-runner 4.2
python-coveralls 2.9.1
python-dateutil 2.7.5
pytz 2018.9
PyYAML 3.13
pyzmq 17.1.2
qtconsole 4.4.3
readme-renderer 24.0
requests 2.18.4
requests-toolbelt 0.8.0
s3transfer 0.1.13
scandir 1.9.0
scipy 1.2.0
Send2Trash 1.5.0
setuptools 40.6.3
simplegeneric 0.8.1
singledispatch 3.4.0.3
six 1.12.0
smmap2 2.0.5
snowballstemmer 1.2.1
Sphinx 1.8.3
sphinx-issues 1.2.0
sphinx-rtd-theme 0.4.2
sphinxcontrib-bibtex 0.4.2
sphinxcontrib-napoleon 0.7
sphinxcontrib-websupport 1.1.0
statistics 1.0.3.5
subprocess32 3.5.3
tensorboard 1.12.2
tensorflow 1.12.0
tensorflow-probability 0.5.0
termcolor 1.1.0
terminado 0.8.1
testpath 0.4.2
textwrap3 0.9.1
toml 0.10.0
torch 1.0.0
tornado 5.1.1
tqdm 4.29.0
traitlets 4.3.2
twine 1.12.1
typing 3.6.6
uproot 3.3.2
uproot-methods 0.3.3
urllib3 1.22
virtualenv 16.2.0
wcwidth 0.1.7
webencodings 0.5.1
Werkzeug 0.14.1
wheel 0.32.3
widgetsnbextension 3.4.2
zipp 0.3.3
python
travis@travis-job-2326826f-1987-469e-80ed-956889b8a731:~/build/diana-hep/pyhf$ which python
/opt/pyenv/shims/python
travis@travis-job-2326826f-1987-469e-80ed-956889b8a731:~/build/diana-hep/pyhf$ python --version
Python 2.7.14
python path
>>> import sys
>>> sys.path
['', '/home/travis/virtualenv/python2.7.14/lib/python27.zip', '/home/travis/virtualenv/python2.7.14/lib/python2.7', '/home/travis/virtualenv/python2.7.14/lib/python2.7/plat-linux2', '/home/travis/virtualenv/python2.7.14/lib/python2.7/lib-tk', '/home/travis/virtualenv/python2.7.14/lib/python2.7/lib-old', '/home/travis/virtualenv/python2.7.14/lib/python2.7/lib-dynload', '/opt/python/2.7.14/lib/python2.7', '/opt/python/2.7.14/lib/python2.7/plat-linux2', '/opt/python/2.7.14/lib/python2.7/lib-tk', '/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages', '/home/travis/build/diana-hep/pyhf']
Background
pyhf is a statistics tool that uses multiple backends for performing tensor calculations. Some of these backends include tensorflow, mxnet, pytorch, etc… We initially observed a segfault:
Segmentation fault: 11
Stack trace returned 10 entries:
[bt] (0) /home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x1e945a) [0x7f4fec78545a]
[bt] (1) /home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x2f891f6) [0x7f4fef5251f6]
[bt] (2) /lib/x86_64-linux-gnu/libc.so.6(+0x36cb0) [0x7f5061593cb0]
[bt] (3) /lib/x86_64-linux-gnu/libpthread.so.0(sem_wait+0) [0x7f5061934640]
[bt] (4) /opt/python/2.7.14/lib/libpython2.7.so.1.0(PyThread_acquire_lock+0x68) [0x7f5061c92578]
[bt] (5) /lib/x86_64-linux-gnu/libcrypto.so.1.0.0(+0x610c0) [0x7f505e3140c0]
[bt] (6) /lib/x86_64-linux-gnu/libcrypto.so.1.0.0(+0x61749) [0x7f505e314749]
[bt] (7) /lib/x86_64-linux-gnu/libssl.so.1.0.0(SSL_CTX_free+0x6e) [0x7f505bd1f8de]
[bt] (8) /home/travis/virtualenv/python2.7.14/lib/python2.7/lib-dynload/_ssl.so(+0xa06b) [0x7f505bf5106b]
[bt] (9) /opt/python/2.7.14/lib/libpython2.7.so.1.0(+0xba17a) [0x7f5061bfe17a]
which we initially believed to be due to changes in pathlib
vs pathlib2
in ionelmc/pytest-benchmark#8469a5.
However, upon doing some debug session with travis, I’ve stumbled upon the fact that pytest
invocation causes a segfault while python -m pytest
does not, even including updating the PYTHONPATH
to take into account the current directory as suggested by pytest
documentation. In summary, the following commands produce the segfault:
pytest tests/test_notebooks.py
PYTHONPATH=. pytest tests/test_notebooks.py
python $(which pytest) tests/test_notebooks.py
The following commands do not produce a segfault:
python -m pytest tests/test_notebooks.py
PYTHONPATH=. python -m pytest tests/test_notebooks.py
/usr/bin/env python -m pytest tests/test_notebooks.py
/home/travis/virtualenv/python2.7.14/bin/python -m pytest tests/test_notebooks.py
Here’s a quick checklist in what to include:
- Include a detailed description of the bug or suggestion
-
pip list
of the virtual environment you are using - pytest and operating system versions
- Minimal example if possible
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:24 (12 by maintainers)
I can reproduce this outside of travis-ci 🎉
dockerfile
build
runtime
Note that this shows two different crashes – the first crashes on a “fresh” run during collection, the second crashes during final-gc. Running a third time shows the same as the final-gc crash.
Interestingly enough,
python -m pytest
is also crashing for me:The vonly difference I could imagine there is the setuptools entry point machinery somehow having a negative side effect. This one sounds like it’s going to be pretty difficult to reproduce!