Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从ThreadPoolExecutor使用Python gRPC客户端_Python_Python Multithreading_Grpc_Concurrent.futures - Fatal编程技术网

从ThreadPoolExecutor使用Python gRPC客户端

从ThreadPoolExecutor使用Python gRPC客户端,python,python-multithreading,grpc,concurrent.futures,Python,Python Multithreading,Grpc,Concurrent.futures,我希望通过从Python客户机发送多个gRPC请求并等待响应来加快处理速度。似乎concurrent.futures.ThreadPoolExecutor非常适合,因为这主要是IO工作。但gRPC客户端似乎从未释放GIL,我无法实现任何加速 我的代码是这样的 def do_call(): return stub.Call(something) futures = [] thread_pool = concurrent.futures.ThreadPoolExecutor(workers

我希望通过从Python客户机发送多个gRPC请求并等待响应来加快处理速度。似乎
concurrent.futures.ThreadPoolExecutor
非常适合,因为这主要是IO工作。但gRPC客户端似乎从未释放GIL,我无法实现任何加速

我的代码是这样的

def do_call():
    return stub.Call(something)

futures = []
thread_pool = concurrent.futures.ThreadPoolExecutor(workers=10)
for _ in range(100):
    futures.append(thread_pool.submit(do_call))

for future in concurrent.futures.as_completed(futures):
    print(future.result())
最后,这比同步调用该方法100次要慢。我可能做错了什么?我尝试使用一个通道,并为每个请求创建一个单独的存根,但这并没有改变任何事情

我知道存根有一个
stub.Call.future()
方法,我可以使用它。我的问题是
do_call()
函数实际上相当复杂,我希望避免在将来将所有处理重写为回调

有什么想法吗