我有一个gRPC它使用的服务器ProcessPoolExecutor与max_workers=1运行一个脚本。这就是为什么我不得不使用ProcessPoolExecutor里面run_brain_application有max_workers=1。下面是服务器脚本的简化版本。
我已经放置了两个打印语句来打印process.
问题是有时,对于某些请求,该过程开始但从未完成。我的意思是它打印START,但我从来没有看到STOP. 下一次相同的请求有效,因此问题不在于请求。此外,如果 内有异常run_application,它会毫无问题地抛出。
我已经检查了 Stackoverflow 上的所有相关问题,但其中大多数(1、2)都是关于他们的进程没有抛出异常,这不是我的情况。
任何想法都非常感谢!
谢谢
class BrainServer(brain_pb2_grpc.BrainServiceServicer):
def run_brain_application(self, request, context):
request_dict = MessageToDict(
request,
preserving_proto_field_name=True,
keep_null=True
)
print("START")
with futures.ProcessPoolExecutor(max_workers=1) as executor:
result = executor.submit(run_application, request_dict).result()
res = result.get('data')
print("STOP")
report = dict_to_protobuf(result_pb2.Result, {res_type: res}, strict=False)
return report
except Exception as e:
_log_fatal(
msg=str(e)
)
raise e
def serve():
server …Run Code Online (Sandbox Code Playgroud)