Description
While using cadquery in multiprocessing environments (ie. multiprocessing and MPI), I've noted a significant number of segfaults during the _bool_op
routine. I generate a number of geometries in my script and see segfaults by around 1,000-10,000 generated geometries. Looking at the backtrace, I believe this issue is caused by the hard-coded op.SetRunParallel(True)
in the _bool_op
method.
I've been able to successfully generate ~1,000,000 geometries without segfault after manually setting this to op.SetRunParallel(False)
.
To Reproduce
I cannot reproduce the issue on command; this seems to be environment/geometry dependent and I can't post the full script here as it's quite large (modeling some complex systems). I can include a simplified version that communicates the idea of the offending script, but this example script doesn't segfault.
import cadquery as cq
from multiprocessing import Pool
def main():
# Run the below function outside the pool to ensure it works correctly
# generate()
with Pool(5) as pool:
while True:
attempts = []
for _ in range(1000):
attempts.append(pool.apply_async(generate))
[attempt.get() for attempt in attempts]
def generate():
obj = (
cq.Workplane('XZ')
.rect(10, 10)
.extrude(10))
split = (
cq.Workplane('YZ', obj.val().Center(), obj.val())
.workplane()
.split(keepBottom=True)
.solids('<Y')
.val())
if __name__ == '__main__':
main()
Backtrace
This is a (scrubbed) backtrace from my program.
Fatal Python error: Segmentation fault
Thread 0x00002ae45476fa00 (most recent call first):
File ".conda/envs/example/lib/python3.8/site-packages/cadquery/occ_impl/shapes.py", line 892 in _bool_op
File ".conda/envs/example/lib/python3.8/site-packages/cadquery/occ_impl/shapes.py", line 2788 in cut
File ".conda/envs/example/lib/python3.8/site-packages/cadquery/cq.py", line 262 in split
...
Environment
OS: Scientific Linux 7.8
# packages in environment at ******:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 1_gnu conda-forge
alsa-lib 1.2.3 h516909a_0 conda-forge
attrs 21.2.0 pyhd3eb1b0_0
backcall 0.2.0 pyh9f0ad1d_0 conda-forge
backports 1.0 py_2 conda-forge
backports.functools_lru_cache 1.6.4 pyhd8ed1ab_0 conda-forge
brotlipy 0.7.0 py38h497a2fe_1001 conda-forge
bzip2 1.0.8 h7f98852_4 conda-forge
c-ares 1.17.1 h7f98852_1 conda-forge
ca-certificates 2021.7.5 h06a4308_1
cached-property 1.5.2 py_0
cadquery 2.1 py3.8 cadquery
certifi 2021.5.30 py38h06a4308_0
cffi 1.14.6 py38ha65f79e_0 conda-forge
chardet 4.0.0 py38h578d9bd_1 conda-forge
charset-normalizer 2.0.0 pyhd8ed1ab_0 conda-forge
conda 4.10.3 py38h578d9bd_0 conda-forge
conda-pack 0.6.0 pyhd3deb0d_0 conda-forge
conda-package-handling 1.7.3 py38h497a2fe_0 conda-forge
cryptography 3.4.7 py38ha5dfef3_0 conda-forge
curl 7.78.0 hea6ffbf_0 conda-forge
cycler 0.10.0 py_2 conda-forge
dbus 1.13.6 h48d8840_2 conda-forge
decorator 5.0.9 pyhd8ed1ab_0 conda-forge
double-conversion 3.1.5 h9c3ff4c_2 conda-forge
eigen 3.3.9 h4bd325d_1 conda-forge
expat 2.4.1 h9c3ff4c_0 conda-forge
ezdxf 0.16.4 py38h1fd1430_0 conda-forge
ffmpeg 4.3.1 hca11adc_2 conda-forge
fontconfig 2.13.1 hba837de_1005 conda-forge
freeimage 3.18.0 h88c329d_7 conda-forge
freetype 2.10.4 h0708190_1 conda-forge
geos 3.9.1 h9c3ff4c_2 conda-forge
gettext 0.19.8.1 h0b5b191_1005 conda-forge
gl2ps 1.4.2 h0708190_0 conda-forge
glew 2.1.0 h9c3ff4c_2 conda-forge
glib 2.68.3 h9c3ff4c_0 conda-forge
glib-tools 2.68.3 h9c3ff4c_0 conda-forge
gmp 6.2.1 h58526e2_0 conda-forge
gnutls 3.6.13 h85f3911_1 conda-forge
gst-plugins-base 1.18.4 hf529b03_2 conda-forge
gstreamer 1.18.4 h76c114f_2 conda-forge
h5py 3.2.1 py38h6c542dc_0
hdf4 4.2.15 h10796ff_3 conda-forge
hdf5 1.10.6 nompi_h6a2412b_1114 conda-forge
icu 68.1 h58526e2_0 conda-forge
idna 3.1 pyhd3deb0d_0 conda-forge
ilmbase 2.5.5 h780b84a_0 conda-forge
imageio 2.9.0 py_0 conda-forge
iniconfig 1.1.1 pyhd3eb1b0_0
ipython 7.25.0 py38hd0cf306_1 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
jbig 2.1 h7f98852_2003 conda-forge
jedi 0.18.0 py38h578d9bd_2 conda-forge
jpeg 9d h36c2ea0_0 conda-forge
jsoncpp 1.9.4 h4bd325d_3 conda-forge
jxrlib 1.1 h7f98852_2 conda-forge
kiwisolver 1.3.1 py38h1fd1430_1 conda-forge
krb5 1.19.2 hcc1bbae_0 conda-forge
lame 3.100 h7f98852_1001 conda-forge
lcms2 2.12 hddcbb42_0 conda-forge
ld_impl_linux-64 2.36.1 hea4e1c9_2 conda-forge
lerc 2.2.1 h9c3ff4c_0 conda-forge
libarchive 3.5.1 hccf745f_2 conda-forge
libblas 3.9.0 10_openblas conda-forge
libcblas 3.9.0 10_openblas conda-forge
libclang 11.1.0 default_ha53f305_1 conda-forge
libcurl 7.78.0 h2574ce0_0 conda-forge
libdeflate 1.7 h7f98852_5 conda-forge
libedit 3.1.20191231 he28a2e2_2 conda-forge
libev 4.33 h516909a_1 conda-forge
libevent 2.1.10 hcdb4288_3 conda-forge
libffi 3.3 h58526e2_2 conda-forge
libgcc-ng 11.1.0 hc902ee8_4 conda-forge
libgfortran-ng 11.1.0 h69a702a_4 conda-forge
libgfortran5 11.1.0 h6c583b3_4 conda-forge
libglib 2.68.3 h3e27bee_0 conda-forge
libglu 9.0.0 he1b5a44_1001 conda-forge
libgomp 11.1.0 hc902ee8_4 conda-forge
libiconv 1.16 h516909a_0 conda-forge
liblapack 3.9.0 10_openblas conda-forge
libllvm11 11.1.0 hf817b99_2 conda-forge
libnetcdf 4.8.0 nompi_hcd642e3_103 conda-forge
libnghttp2 1.43.0 h812cca2_0 conda-forge
libogg 1.3.4 h7f98852_1 conda-forge
libopenblas 0.3.17 pthreads_h8fe5266_1 conda-forge
libopus 1.3.1 h7f98852_1 conda-forge
libpng 1.6.37 h21135ba_2 conda-forge
libpq 13.3 hd57d9b9_0 conda-forge
libraw 0.20.2 h10796ff_1 conda-forge
libsolv 0.7.19 h780b84a_5 conda-forge
libssh2 1.9.0 ha56f1ee_6 conda-forge
libstdcxx-ng 11.1.0 h56837e0_4 conda-forge
libtheora 1.1.1 h7f98852_1005 conda-forge
libtiff 4.3.0 hf544144_1 conda-forge
libuuid 2.32.1 h7f98852_1000 conda-forge
libvorbis 1.3.7 h9c3ff4c_0 conda-forge
libwebp-base 1.2.0 h7f98852_2 conda-forge
libxcb 1.13 h7f98852_1003 conda-forge
libxkbcommon 1.0.3 he3ba5ed_0 conda-forge
libxml2 2.9.12 h72842e0_0 conda-forge
libzip 1.8.0 h4de3113_0 conda-forge
loguru 0.5.3 py38h578d9bd_2 conda-forge
lz4-c 1.9.3 h9c3ff4c_0 conda-forge
lzo 2.10 h516909a_1000 conda-forge
mamba 0.15.2 py38h2aa5da1_0 conda-forge
matplotlib 3.4.2 py38h578d9bd_0 conda-forge
matplotlib-base 3.4.2 py38hcc49a3a_0 conda-forge
matplotlib-inline 0.1.2 pyhd8ed1ab_2 conda-forge
more-itertools 8.8.0 pyhd3eb1b0_0
mpi 1.0 mpich
mpi4py 3.1.1 pypi_0 pypi
mpich 3.3.2 external_0
mysql-common 8.0.25 ha770c72_2 conda-forge
mysql-libs 8.0.25 hfa10184_2 conda-forge
ncurses 6.2 h58526e2_4 conda-forge
nettle 3.6 he412f7d_0 conda-forge
nptyping 1.4.2 pyhd8ed1ab_0 conda-forge
nspr 4.30 h9c3ff4c_0 conda-forge
nss 3.67 hb5efdd6_0 conda-forge
numpy 1.21.1 py38h9894fe3_0 conda-forge
occt 7.4.0 h74ec91c_8 conda-forge
ocp 7.4 1_py3.8 cadquery
olefile 0.46 pyh9f0ad1d_1 conda-forge
openexr 2.5.5 hf817b99_0 conda-forge
openh264 2.1.1 h780b84a_0 conda-forge
openjpeg 2.4.0 hb52868f_1 conda-forge
openssl 1.1.1k h27cfd23_0
packaging 21.0 pyhd3eb1b0_0
pandas 1.3.1 py38h1abd341_0 conda-forge
parso 0.8.2 pyhd8ed1ab_0 conda-forge
pcre 8.45 h9c3ff4c_0 conda-forge
pexpect 4.8.0 py38h32f6830_1 conda-forge
pickleshare 0.7.5 py38h32f6830_1002 conda-forge
pillow 8.3.1 py38h8e6f84c_0 conda-forge
pip 21.2.1 pyhd8ed1ab_0 conda-forge
pluggy 0.13.1 py38h06a4308_0
proj 7.2.0 h277dcde_2 conda-forge
prompt-toolkit 3.0.19 pyha770c72_0 conda-forge
pthread-stubs 0.4 h36c2ea0_1001 conda-forge
ptyprocess 0.7.0 pyhd3deb0d_0 conda-forge
pugixml 1.11.4 h9c3ff4c_0 conda-forge
py 1.10.0 pyhd3eb1b0_0
pycosat 0.6.3 py38h497a2fe_1006 conda-forge
pycparser 2.20 pyh9f0ad1d_2 conda-forge
pygments 2.9.0 pyhd8ed1ab_0 conda-forge
pyopenssl 20.0.1 pyhd8ed1ab_0 conda-forge
pyparsing 2.4.7 pyh9f0ad1d_0 conda-forge
pyqt 5.12.3 py38h578d9bd_7 conda-forge
pyqt-impl 5.12.3 py38h7400c14_7 conda-forge
pyqt5-sip 4.19.18 py38h709712a_7 conda-forge
pyqtchart 5.12 py38h7400c14_7 conda-forge
pyqtwebengine 5.12.1 py38h7400c14_7 conda-forge
pysocks 1.7.1 py38h578d9bd_3 conda-forge
pytest 6.2.4 py38h06a4308_2
python 3.8.10 h49503c6_1_cpython conda-forge
python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge
python_abi 3.8 2_cp38 conda-forge
pytz 2021.1 pyhd8ed1ab_0 conda-forge
qt 5.12.9 hda022c4_4 conda-forge
readline 8.1 h46c0cb4_0 conda-forge
reproc 14.2.1 h36c2ea0_0 conda-forge
reproc-cpp 14.2.1 h58526e2_0 conda-forge
requests 2.26.0 pyhd8ed1ab_0 conda-forge
ruamel 1.0 py38h578d9bd_4 conda-forge
ruamel.yaml 0.17.10 py38h497a2fe_0 conda-forge
ruamel.yaml.clib 0.2.2 py38h497a2fe_2 conda-forge
ruamel_yaml 0.15.80 py38h497a2fe_1004 conda-forge
scipy 1.7.0 py38h7b17777_1 conda-forge
setuptools 49.6.0 py38h578d9bd_3 conda-forge
shapely 1.7.1 py38haeee4fe_5 conda-forge
six 1.16.0 pyh6c4a22f_0 conda-forge
sqlite 3.36.0 h9cd32fc_0 conda-forge
tbb 2020.2 h4bd325d_4 conda-forge
tbb-devel 2020.2 h4bd325d_4 conda-forge
tk 8.6.10 h21135ba_1 conda-forge
toml 0.10.2 pyhd3eb1b0_0
tornado 6.1 py38h497a2fe_1 conda-forge
tqdm 4.61.2 pyhd8ed1ab_1 conda-forge
traitlets 5.0.5 py_0 conda-forge
typing_extensions 3.10.0.0 pyha770c72_0 conda-forge
typish 1.9.2 pyhd8ed1ab_0 conda-forge
urllib3 1.26.6 pyhd8ed1ab_0 conda-forge
utfcpp 3.2.1 ha770c72_0 conda-forge
vtk 9.0.1 no_osmesa_py38h3850a3d_109 conda-forge
wcwidth 0.2.5 pyh9f0ad1d_2 conda-forge
wheel 0.36.2 pyhd3deb0d_0 conda-forge
x264 1!161.3030 h7f98852_1 conda-forge
xorg-kbproto 1.0.7 h7f98852_1002 conda-forge
xorg-libice 1.0.10 h7f98852_0 conda-forge
xorg-libsm 1.2.3 hd9c2040_1000 conda-forge
xorg-libx11 1.7.2 h7f98852_0 conda-forge
xorg-libxau 1.0.9 h7f98852_0 conda-forge
xorg-libxdmcp 1.1.3 h7f98852_0 conda-forge
xorg-libxext 1.3.4 h7f98852_1 conda-forge
xorg-libxt 1.2.1 h7f98852_2 conda-forge
xorg-xextproto 7.3.0 h7f98852_1002 conda-forge
xorg-xproto 7.0.31 h7f98852_1007 conda-forge
xz 5.2.5 h516909a_1 conda-forge
yaml 0.2.5 h516909a_0 conda-forge
zlib 1.2.11 h516909a_1010 conda-forge
zstd 1.5.0 ha95c52a_0 conda-forge
Using: