如何并行化CadQuery或导入`cq_serialize`?

huangapple go评论93阅读模式
英文:

How to parallelize CadQuery or import `cq_serialize`

问题

我尝试像在这里讨论的那样对CadQuery进行序列化,例如使用以下代码:

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))

不幸的是,在CadQuery版本2.3.0.dev0中,模块cq_serialize似乎已经消失或更名。至少我得到了一个ModuleNotFoundError: No module named 'cq_serialize'错误。

此外,在GitHub项目中没有关于serialize的线索。

是否有任何提示如何导入cq_serialize,或者如何在CadQuery中实现并行化?

如果我只是删除register_cq_helper()部分,代码将不再终止。我认为这是为了处理一些内部通知调用而需要的。

我不想盲目地调用CadQuery并行化,因为内核似乎已经有时会崩溃。

英文:

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

得分: 1

提到的序列化助手并不是 CadQuery 的一部分。如果你想使用它们,你需要将引用的文件添加到你的项目中。你也可以在这里找到它:https://gist.github.com/SDI8/3137ee70649e4901913c7c8e6b534ec8

这些助手适用于许多类型的 CadQuery 对象,但并不适用于所有对象。如果需要的话,可以随时添加更多助手。

免责声明,我就是 cq_serialize 的作者。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月27日 17:54:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76778555.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定