英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论