Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 983
saurabhsood91 Avatar asked Nov 08 '17 19:11

saurabhsood91


1 Answers

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

Try updating to gRPC 1.7.

like image 179
kpayson64 Avatar answered Nov 13 '22 14:11

kpayson64