How to parallelize CadQuery or import `cq_serialize`

96 views Asked by At

I try to serialize CadQuery like discussed hier with e.g. this code:

from multiprocessing import Pool
import cadquery as cq
from cq_serialize import register as register_cq_helper

register_cq_helper()

def make_box(size: float):
    return cq.Workplane("XY").box(size, size, size).findSolid()

with Pool() as p:
    boxes = p.map(make_box, range(1, 10))

Sadly, it looks like in CadQuery Version: 2.3.0.dev0 the module cq_serialize seems to be gone or renamed. At least i get a ModuleNotFoundError: No module named 'cq_serialize'error.

Also, in the github project is no clue for serialize

Is there any hint how to either import cq_serialize, or how to achieve parallelization in CadQuery?

If I just remove the register_cq_helper() part the code will not terminate anymore. I assume it is required to handle some internal notify calls.

I don't want to blindly call CadQuery parallel as the kernel already now seems to crash sometimes.

1

There are 1 answers

0
SDI8 On BEST ANSWER

The serializing helpers mentioned are not part of CadQuery as such. If you want to use them, you'll need to add the referenced file to your project. You can also find it here https://gist.github.com/SDI8/3137ee70649e4901913c7c8e6b534ec8

The helpers work for many types of CadQuery objects, but not all. Feel free to add more if need be.

Disclaimer, I'm the guy behind cq_serialize.