在使用DPF-Core时,使用以下代码报错。
from ansys.dpf.core import Model
from ansys.dpf.core import examples
path1 = examples.find_simple_bar()
path2 = examples.download_transient_result()
model = Model(path1)
print(model)
报错:
raise _InactiveRpcError(state) # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNIMPLEMENTED
details = ""
debug_error_string = "UNKNOWN:Error received from peer {grpc_message:"", grpc_status:12, created_time:"2023-12-21T09:35:09.1882508+00:00"}"
>
解决:
搜了搜很多回答说以下方法可以:
关闭代理。
unset http_proxy; unset https_proxy; python server.py &
unset http_proxy; unset https_proxy; python client.py
我还发现额外的 options
可以传递给 grpc.insecure_channel
。
channel = grpc.insecure_channel('localhost:5005', options=(('grpc.enable_http_proxy', 0),))
参考:
我试了上面的没用,他们很多是在用爬虫或者用grpc_client.py这个东西的时候报错的,没看到是在是用pyansys中的DPF-Core出错的。
找了很多资料,最后发现在代码中加入下面这行,这个可以连接到现有服务器(本地或远程),
ansys.dpf.core.connect_to_server()
参考官网的说法:第一次创建 DPF 对象时,Python 会自动尝试在后台启动服务器。如果您想连接到现有服务器(本地或远程),请使用 ansys.dpf.core.connect_to_server()
。
Basic DPF-Core usage — PyDPF-Core --- DPF-Core 基本用法 — PyDPF-Core (pyansys.com)
最后代码如下:
import ansys
from ansys.mapdl.core import launch_mapdl
from ansys.mapdl.core import examples
from ansys.mapdl import reader as pymapdl_reader
from ansys.dpf import core as dpf
from ansys.dpf.core import Model
from ansys.dpf.core import examples
path1 = examples.find_simple_bar()
path2 = examples.download_transient_result()
ansys.dpf.core.connect_to_server()
print(path1)
# model = Model(path)
# print(model)
这个东西我运行几次代码它就运行几次,占cpu很多,后来直接给我顶到100%了,卡死,得从管理器给它关掉。