解决raise _InactiveRpcError(state)grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that ...

文章讲述了在使用DPF-Core时遇到的gRPC错误,特别是_InactiveRpcError,通过关闭代理、调整grpc连接设置和使用`connect_to_server`函数连接服务器来解决问题。然而,连接服务器导致CPU占用过高,最终导致程序崩溃。
摘要由CSDN通过智能技术生成

在使用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),))

参考:

python 3.x - grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE - Stack Overflow --- python 3.x - grpc._channel._InactiveRpcError:< RPC的_InactiveRpcError终止于:status = StatusCode.UNAVAILABLE - VoidCC

我试了上面的没用,他们很多是在用爬虫或者用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%了,卡死,得从管理器给它关掉。

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值