我们在 EC2 上运行的 Docker 容器内有一个机器学习模型。
我们使用 Cortex.dev 来自动缩放 GPU。
不确定性的是,请求将在call_nextFastAPI 中间件的函数执行过程中挂起。不幸的是,它是不可重现的。
打印Middleware pre-request行被记录,但路径操作函数中的第一个打印语句永远不会被记录。
我们尝试过的事情:
run函数在没有异步的情况下运行bytes作为参数类型 forimage而不是UploadFile这些更改都不能解决挂起问题,但这是性能最高的配置。
这是否意味着问题出在 FastAPI 而不是 Uvicorn?
如果是,什么可能导致 FastAPI 挂起?如果不是,问题出在哪里以及如何解决?
Dockerfile
FROM nvidia/cuda:11.4.0-runtime-ubuntu18.04
WORKDIR /usr/src/app
RUN apt-get -y update && \
apt-get install -y --fix-missing \
build-essential \
cmake \
python3 \
python3-pip \
ffmpeg \
libsm6 \
libxext6 \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
ADD ./requirements.txt …Run Code Online (Sandbox Code Playgroud) 如果这是一个重复的问题,我很抱歉,但除了这个网站之外,我几乎在任何地方都看不到它。这个网站最初是帮助人们通过 REST API 在 Google Sheet 中进行查询。他们的链接就像这个例子:
spreadsheetID/sheetName?filter[ColumnName]=aiman
Run Code Online (Sandbox Code Playgroud)
我只是想知道如何在 FastAPI 中执行此操作,特别是对于 params filter[columnName]。columnName 也是一个根据列名称的变量。我已经读过这篇文章但无法很好地理解它。我也欣赏任何语言。
我试图在 FastApi 路由中运行子进程,但执行结果为NotImplementedError. 我读过有关该问题的类似问题:
为什么我在 Windows 上使用 async 和 wait 时会收到 NotImplementedError 错误?
Asyncio.create_subprocess_exec NotImplementedError - Fastapi 后台任务
但他们似乎没有任何可行的解决方案。
我的 FastApi 路线如下所示:
@app.get("/test/subprocess")
async def subprocess_test():
parsed_json = await(probe_video_file(Path(r"G:\ffmpeg testing\ffmpeg\ffprobe.exe"),
Path(r"G:\ffmpeg testing\input_file\test_file.wmv")))
print(parsed_json)
return parsed_json
Run Code Online (Sandbox Code Playgroud)
当我导航到此路径时,会引发异常并且代码崩溃。该probe_video_file函数内部有一个子进程调用,如下所示:
async def probe_video_file(ffprobe_path: Path, file_to_probe: Path) -> dict:
"""
Probes a video file with FFprobe.
:param ffprobe_path: Path to ffprobe executable
:param file_to_probe: Path to file to probe
:returns Parsed JSON dict of the output
"""
args = …Run Code Online (Sandbox Code Playgroud) 客户端可能会发送多个查询参数,例如:
# method = POST
http://api.com?x=foo&y=bar
Run Code Online (Sandbox Code Playgroud)
我需要从 POST 请求中获取所有查询参数并将extract其作为字符串。x=foo&y=bar
有没有办法做到这一点fast api?我在他们的文档中找不到它。
我们not事先就确定了参数的名称。
我正在尝试与指纹设备进行通信。实际上它通过连接发送数据websocket。所以,我想我可以使用 与设备进行通信webscokets。这里我使用FastAPI,但它只接受JSON数据。问题是我需要处理XML数据,但是,我不知道如何以XML格式发送和接受数据。
我遇到过这个问题,虽然它一定是一个常见问题,但我看不到任何解决方案。所以,也许我在这里遗漏了一些东西。
我正在开发具有异步端点和与数据库异步连接的 FastAPI 应用程序。数据库连接作为依赖项传递。我想为所述应用程序编写一些异步测试。
engine = create_async_engine(connection_string, echo=True)
def get_session():
return sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
@router.post("/register")
async def register(
user_data: UserRequest,
authorize: AuthJWT = Depends(),
async_session: sessionmaker = Depends(get_session),
):
"""Register new user."""
if authorize.get_jwt_subject():
raise LogicException("already authorized")
session: AsyncSession
async with async_session() as session:
query = await session.execute(
select(UserModel).where(UserModel.name == user_data.name)
)
...
Run Code Online (Sandbox Code Playgroud)
我正在使用 AsyncSession 来处理数据库。所以在我的测试中,数据库连接也必须是异步的。
engine = create_async_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
app.dependency_overrides[get_session] = lambda: sessionmaker(
engine, class_=AsyncSession, expire_on_commit=False
)
@pytest.mark.asyncio
async def test_create_user():
async with engine.begin() as conn: …Run Code Online (Sandbox Code Playgroud) 我有一个使用 uvicorn 执行的 FastAPI api 代码。现在我想添加一个队列系统,我认为 Celery 和 Flower 对我来说是很好的工具,因为我的 api 有一些端点使用大量 CPU 并且需要几秒钟的时间来响应。但是,我对添加芹菜有几个问题:
我正在使用 fastapi 制作一个 REST API。
我只是想知道为什么每当我执行服务器时都会收到以下消息。
INFO: Started server process [97154]
INFO: Waiting for application startup.
INFO: Application startup complete.
--- Logging error ---
Traceback (most recent call last):
File "/usr/lib/python3.10/logging/__init__.py", line 1100, in emit
msg = self.format(record)
File "/usr/lib/python3.10/logging/__init__.py", line 943, in format
return fmt.format(record)
File "/usr/lib/python3.10/logging/__init__.py", line 678, in format
record.message = record.getMessage()
File "/usr/lib/python3.10/logging/__init__.py", line 368, in getMessage
msg = msg % self.args
TypeError: %d format: a real number is required, not str
Call stack:
File "mYlOcAtIoN/src/main.py", …Run Code Online (Sandbox Code Playgroud) 如何使用 FastAPI 中的套接字实现一个全面的聊天系统。具体请记住以下几点:
我查看了一些库,但遗憾的是,实际有用的实现还很遥远。
任何建议或重定向到获取更多信息的地方都会有很大帮助!
我目前正在使用 FastAPI 构建后端,并且在使用诗歌脚本运行后端时遇到一些问题。这是我的项目结构:
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 backend\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 asgi.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Dockerfile\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 poetry.lock\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pyproject.toml\nRun Code Online (Sandbox Code Playgroud)\npyproject.toml
\n[tool.poetry]\nname = "backend"\nversion = "0.1.0"\ndescription = ""\nauthors = ["Pierre-Alexandre35 <46579114+pamousset75@users.noreply.github.com>"]\nreadme = "README.md"\n\n[tool.poetry.dependencies]\npython = "^3.9"\nuvicorn = "^0.17.6"\nfastapi = "^0.78.0"\npsycopg2 = "^2.9.3"\njwt = "^1.3.1"\npython-multipart = "^0.0.5"\n\n\n[build-system]\nrequires = ["poetry-core"]\nbuild-backend = "poetry.core.masonry.api"\n\n[tool.poetry.scripts]\nfoo='asgi:__main__'\nRun Code Online (Sandbox Code Playgroud)\n如果我正在运行 poetry run python asgi.py,它工作得很好,但如果我使用poetry foo脚本,我会得到No file/folder found for package backend。这些都是我尝试过的组合,每个组合都有相同的错误poetry run foo:
foo='asgi:main'\nfoo='backend.asgi:__main__'\nfoo='backend.asgi:main'\nfoo='backend.asgi:.'\nRun Code Online (Sandbox Code Playgroud)\n