简体   繁体   中英

gunicorn server hangs when calling itself

I have a Django REST Framework service that runs on a gunicorn server. Here is what the config looks like:

exec gunicorn \
        --pid /web/gunicorn.pid \
        --workers 4 \
        --threads 8 \
        --worker-class gthread \
        --name my-api \
        --chdir /src/api \
        --bind unix:/web/.sock \
        --timeout 300 \
        --limit-request-line 8190 \
        wsgi:application

I have two views:

def view1(request):
  # Call DB etc.

def view2(request):
  my_api_python_client.call_view1(request)  # Hangs!

This results in the requesting hanging indefinitely. I understand that calling one view from another sounds counter-intuitive but it has to be done to leverage caching, async calls etc.

What is curious is that when I run it as a Pycharm server, it works perfectly well!

Question - Why does my request never get processed? How do I fix it?

You should check your configuration of gunicorn worker, it have to be more than 1 to run a thread that will call itself.

For example: (2n+1 as number of processors)

gunicorn app.wsgi:application --workers=4 --bind 0.0.0.0:8000 

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