gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

'gunicorn -w 2 -t 2 --worker-class=gevent main:app' fail to start example main.py

Open adielsa opened this issue 2 years ago • 4 comments

Hey, Most basic example of code just try to run multithread

Code: ` import logging

if name == "main": logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) # TODO read from config

from fastapi import FastAPI, Depends, Header, HTTPException

app = FastAPI() `

Command: gunicorn -w 2 -t 2 --worker-class=gevent main:app

Error: Traceback (most recent call last): File "/xxx/venv/lib/python3.9/site-packages/gunicorn/workers/base_async.py", line 55, in handle self.handle_request(listener_name, req, client, addr) File "/xxx/venv/lib/python3.9/site-packages/gunicorn/workers/ggevent.py", line 127, in handle_request super().handle_request(listener_name, req, sock, addr) File "/xxx/venv/lib/python3.9/site-packages/gunicorn/workers/base_async.py", line 108, in handle_request respiter = self.wsgi(environ, resp.start_response) TypeError: __call__() missing 1 required positional argument: 'send'

adielsa avatar Jul 10 '22 19:07 adielsa

I am not exactly clear of repro steps. I tried following main.py

import logging

if __name__ == "main":
    logging.basicConfig(level=logging.DEBUG)
else:
    logging.basicConfig(level=logging.INFO) # TODO read from config

from fastapi import FastAPI, Depends, Header, HTTPException

app = FastAPI()

pip freeze

anyio==3.6.1
fastapi==0.79.0
gevent==21.12.0
greenlet==1.1.2
gunicorn==20.1.0
idna==3.3
pkg_resources==0.0.0
pydantic==1.9.1
sniffio==1.2.0
starlette==0.19.1
typing_extensions==4.3.0
zope.event==4.5.0
zope.interface==5.4.0

It worked fine with given command:

gunicorn -w 2 -t 2 --worker-class=gevent main:app

Am I missing something?

itsankitkp avatar Jul 18 '22 15:07 itsankitkp

Hey, Thanks for looking into it. The fastapi load using guincorn the server error apper when you try to access http://127.0.0.1:8080 the deault website of fastapi failed

but when running with uvicorn its work fine

adielsa avatar Jul 18 '22 15:07 adielsa

Hey, Thanks for looking into it. The fastapi load using guincorn the server error apper when you try to access http://127.0.0.1:8080 the deault website of fastapi failed

but when running with uvicorn its work fine

Thanks for clearing it up. It repros for me as well now

itsankitkp avatar Jul 18 '22 15:07 itsankitkp

May it is by the design? Quoting things here:

WSGI servers is not compatible with FastAPI, FastAPI only runs in ASGI server, 
gunicorn and all the other WSGI servers just implements PEP Standards with 
ASGI workers in depth they still work as ASGI with the workers.

https://stackoverflow.com/questions/63099843/how-can-i-fix-fastapi-application-error-on-apache-wsgi

itsankitkp avatar Jul 18 '22 15:07 itsankitkp