简体   繁体   中英

grpc timeout in a celery task

I am trying to connect to a GRPC server in a celery task. I have the following piece of code

    timeout = 1
    host = '0.tcp.ngrok.io'
    port = '7145'
    channel = grpc.insecure_channel('{0}:{1}'.format(host, port))
    try:
        grpc.channel_ready_future(channel).result(timeout=timeout)
    except grpc.FutureTimeoutError:
        sys.exit(1)
    stub = stub(channel)

When I run this snippet through the Python shell, I am able to establish the connection, and execute the GRPC methods. However, when I run this through the Celery task, I get the grpc.FutureTimeoutError , and the connection does not get established.

The Celery worker lies on the same machine as the grpc server. I tried using the socket library to ping the GRPC server, and that worked (It returned some junk response).

I am using Python 2.7, with grpcio==1.6.0 installed. The Celery version is 4.1.0. Any pointers would be helpful.

I believe Celery uses fork under the hood, and gRPC 1.6 did not support any forking behavior.

Try updating to gRPC 1.7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM