pygmsh
pygmsh copied to clipboard
gmsh report error "signal only works in main thread"
I'm not familiar with gmsh and I want to use pygmsh to subdivide mesh in a grpc request. But it seems gmsh limits multi-threading support in default.
...
File "gmshutil.py", line 22, in subdivide_obj
mesh = geom.generate_mesh()
File "python3.6/site-packages/pygmsh/common/geometry.py", line 54, in __exit__
gmsh.finalize()
File "python3.6/site-packages/gmsh.py", line 261, in finalize
signal.signal(signal.SIGINT, oldsig)
File "python3.6/signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
I read http://gmsh.info/doc/texinfo/gmsh.html and tried solutions in #317
gmsh.option.setNumber('General.NumThreads', 32)
# OR
gmsh.option.setNumber('Mesh.Algorithm3D', 32)
But problem's not solved.
Could somebody help?
Upvoted. I have the same error calling gmsh from FastAPI endpoints. I'm guessing the server is using the main thread and the error comes about when gmsh is executed in a worker thread. Will let you know if I get anywhere :)
@thisistheplace were you able to fix the error?
Hi, I ended up running gmsh in a separate process to the server and using a messaging queue.
E.g. gmsh gets called in this line:
https://github.com/thisistheplace/joint_model/blob/ab3aa2985908846698d6358c3a51dc56dbee738a/src/app/server/worker/worker.py#L84
Thanks for the response. I will try that!