【问题标题】:Multi-threading python calls to Google Cloud Vision API对 Google Cloud Vision API 的多线程 python 调用
【发布时间】:2017-11-22 06:29:40
【问题描述】:

我在 macOS 机器支持的 Docker 容器中运行服务器,我需要从中发送多个图像以供 Google Cloud Vision API 处理。

我必须能够最大限度地减少上传和处理图像所花费的时间。

我首先将 GCV 调用包装在 Queue.QueueThreading.Thread 中,但这偶尔会导致我的代码崩溃(不是被 python Exception 困住)因此:

E1121 14:15:10.902211037   25448 sync_posix.c:38]            assertion failed: pthread_mutex_destroy(mu) == 0

根据几个 github 线程,这是一个受 gRPC 启发(或 httplib?)的错误/功能,但我找不到简单解决方法的步骤 - 参见例如https://github.com/grpc/grpc/issues/11184https://github.com/grpc/grpc/issues/10909

鉴于这似乎是一个普遍遇到的问题,没有明确的解决方案,缓解它的最佳方法是什么?

是否像使用单个 Batch 调用(但整体速度呢?)到 GCV 一样简单?没有其他方法可以安全地线程调用吗?

更新:

由于担心损坏,我开始将 gRPC 回滚到 v1.2.x 一个 la

https://github.com/grpc/grpc/issues/10909#issuecomment-302581954

除了我必须在我的 Docker 容器中将/usr/local/lib 添加到LD_LIBRARY_PATH 才能获取libprotobuf.so.12

我没有对任何其他 python 包进行任何更改。

然后我做了:

pip install grpcio==1.2.1

显然这会变得昂贵,但与之前的 1/3 调用相比,崩溃率是

现在:我如何才能确定地测试此问题是否已修复?

【问题讨论】:

    标签: python multithreading google-cloud-vision


    【解决方案1】:

    这是我使用的 Dockerfile 的相关部分(基于 https://github.com/grpc/grpc/issues/10909#issuecomment-302581954

    # gRPC fix (rollback to v1.2.x to mitigate mutex crashing bug)
    RUN apt-get install -y build-essential autoconf libtool
    RUN apt-get install -y libgflags-dev libgtest-dev
    RUN apt-get install -y clang libc++-dev
    RUN apt-get install -y sudo unzip locate
    RUN mkdir -p /app/src
    
    WORKDIR /app/src
    RUN git clone --branch v1.2.x https://github.com/grpc/grpc
    
    WORKDIR /app/src/grpc
    RUN git submodule foreach git clean -xfd
    RUN git submodule update --init
    
    WORKDIR /app/src/grpc/third_party/protobuf
    RUN ./autogen.sh
    RUN ./configure
    RUN make -j2
    RUN sudo make install
    
    WORKDIR /app/src/grpc
    RUN sudo make install
    ENV LD_LIBRARY_PATH=${LD_LIBRARY}:/usr/local/lib
    RUN pip install --trusted-host pypi.python.org grpcio==1.2.1
    RUN pip install --trusted-host pypi.python.org google-cloud-vision
    

    我会让这个打开几天看看是否有人回应。

    【讨论】:

      猜你喜欢
      • 2018-08-13
      • 2020-01-12
      • 2017-07-07
      • 1970-01-01
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-06-10
      • 2016-08-24
      相关资源
      最近更新 更多