abersheeran / a2wsgi

Convert WSGI app to ASGI app or ASGI app to WSGI app.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Converting FastAPI app to WSGI and use it on cPanel

keyvan-najafy opened this issue · comments

commented

Hi
I have a very simple FastAPI app which I need to run on a host with cPanel
when I convert my app using a2wsgi and test it on local host using Werkzeug package (which only supports WSGI therefor cant run FastAPI app without conversion ) it works fine but when I deploy it on cPanel server takes too long to process and the returns this

image

I also tried to avoid cPanel regular UI for creating python apps and used terminal to deploy instead but the result is the same
Can anyone help me with this ?

commented

I'm not familiar with cPanel. But the following code maybe have help for you to debuging:

app = your_app

async def log_middleware(scope, receive, send):
    async def _receive():
        msg = await receive()
        print(msg)
        return msg

    async def _send(msg):
        print(msg)
        await send(msg)

     return await app(scope, _receive, _send)

Read the output, you can know where the code is hanging.

commented

This is the only output even with an additional logger and middleware:
2021-08-17 17:22:13.478701 [UID:1361][1070483] Child process with pid: 1070487 was killed by signal: 15, core dump: 0
but the code stays same like before.

commented

It's look like your fastapi process be killed.

commented

Sadly I switched to a cloud service with docker so I cant comment on this anymore but I used the same method on passenger_wsgi.py.
As for API domain I did not used what you said so maybe that was the problem.
Also my cPanel version was a bit old so it would be great if you share yours

commented

This was closed but is the only place I found help to start to get through this same problem so will share here for others running into it.
I was getting the exact same error message in my stderr.log in the python app folder regards child processes until I changed the code in passenger_wsgi.py to from main import app with main.py being my code. But then I started getting 503 errors and found a lot of others had that too with django attempts (I am using FastAPI).

Nothing shows up in the CPanel metrics errors other than "503 - file missing", and no more errors were being added to the stderr.log which was weird... first thing I tried was stopping and starting the python app but still nothing.

So do this for better debugging info... run the python code from the terminal in CPanel using the source code it gives you in python app setup config at the top and then type "python passenger_wsgi.py"

one problem is the indentation in the debug code snippet shared by abersheeran if you copy and past it the code wont run, and it needs the single white space removed from the line that starts return await app(scope, _receive, _send) . the only place you will see this problem is if you try to run it in the terminal.

now my code runs without the 503 error, but runs the wrong thing, but it does run from a browser. I have now hit other issues but will share the solution if I find them. I believe the initial problem to this working might have been hindered by that white space issue .

commented

didnt solve it. I also set it up on it's own subdomain as per christophe-deleuze suggestion and when I add the fast-api main.py back in it fails to work and I get the dreaded [UID:1293][19858] Child process with pid: 20085 was killed by signal: 15, core dump: 0 error which seems to be common for everyone and have no solutions suggested anywhere at this time.

commented

All seem to be caused by the process being killed.

commented

for some, and not others. shame no one has found a cause or solution. I have given it one last shot by posting the issue on stackoverflow. after that I am going to have to look at server hosting it.