Comment 3 for bug 1970557

Revision history for this message
Enrique (enrique-garcia) wrote :

I also confirm that this bug renders the current installation of fastapi in Ubuntu 22.04 unusable. I have used a virtual environment to install a new version of fastapi while using the rest of the packages from the system as follows:

# python3 -m venv --system-site-packages
# pip install fastapi==0.76

I then have tested that with the following self-contained test works fine:
import requests

import threading
import unittest
from time import sleep
import uvicorn.server

from fastapi import FastAPI

app = FastAPI()

@app.get("/ping")
def get_object() :
    return {"ping": "OK"}

class FastAPITest(unittest.TestCase):
    server: uvicorn.server.Server = None

    def __init__(self, args):
        super().__init__(args)

    @classmethod
    def setUpClass(cls):
        from uvicorn.config import Config
        from uvicorn import Server
        uvicorn_config = Config(app, port=8888, host="localhost")
        FastAPITest.server = Server(config=uvicorn_config)
        threading.Thread(target=FastAPITest.server.run).start()
        sleep(1)

    @classmethod
    def tearDownClass(cls):
        FastAPITest.server.should_exit = True
        sleep(1)

    def test_ping(self):
        requests.get("http://localhost:8888/ping")

As previous comment said, version 0.76 of fastapi would be compatible with the installed versions of both starlette and uvicorn and will solve the issue.