uvicorn

Nginx reverse proxy on unix socket for uvicorn not working

≯℡__Kan透↙ 提交于 2020-08-08 06:13:36
问题 Files : # main.py: from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} - # nginx.conf: events { worker_connections 128; } http{ server { listen 0.0.0.0:8080; location / { include uwsgi_params; uwsgi_pass unix:/tmp/uvi.sock; } } } - # Dockerfile FROM python:3 COPY main.py . RUN apt-get -y update && apt-get install -y htop tmux vim nginx RUN pip install fastapi uvicorn COPY nginx.conf /etc/nginx/ Setup : docker build -t nginx-uvicorn:latest .

FastAPI throws an error (Error loading ASGI app. Could not import module “api”)

不想你离开。 提交于 2020-08-07 06:46:20
问题 I tried to run FastAPI using uvicorn webserver but it throws an error. I run this command, uvicorn api:app --reload --host 0.0.0.0 but there is an error in the terminal. Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) Started reloader process [23445] Error loading ASGI app. Could not import module "api". Stopping reloader process [23445] I really appreciate any recommendations or suggestions 回答1: It happens because you are not in the same folder with your FastAPI app instance

性能是Flask的3倍!比PHP7还快!这个Python框架你值得拥有!

可紊 提交于 2020-05-05 10:45:09
天下武功,唯快不破。在软件开发中更是如此,“快”能从多方面提升用户体验。谈到Python,它似乎天生就和速度无关,你可能很熟悉Django、Flask这些框架,虽然开发效率的确不错,但是速度就一言难尽。那么在前后端分离开发的时代,有没有能拿得出手的Python Web框架呢?当然是有的,FastApi它来了。 一、为什么是FastApi? 人们在介绍FastApi的时候通常会说“FastApi”是一个高性能的异步WEB框架。我相信没有哪个程序员会跟“高性能”过不去,这往往也是我们所追求的东西。fastapi具有并发性能强、能够快速上手、容错能力强、自动生成交互式文档的特点,这些都是我们选择它的理由。 二、到底有多快? 很多人介绍FastApi框架时,经常说其并发性能能够和NodeJS以及Go媲美,其实言过其实。在Go语言中文社区中梦想做小猿分别对Go、Flask、FastApi做了性能测试,迫于篇幅限制,我这里直接放结果: FastAPI:500并发 30秒:Speed=955466 pages/min, 238685 bytes/sec Flask:500并发 30秒:Speed=33706 pages/min, 96457 bytes/sec Go:500并发 30秒:Speed=116962 pages/min, 278740 bytes/sec 可见Go还是很强大的

(完结篇)Python框架之FastAPI——一个比Flask和Tornado更高性能的API 框架

我与影子孤独终老i 提交于 2020-04-17 09:10:24
【推荐阅读】微服务还能火多久?>>> 0 前言 前几天给大家分别分享了 (入门篇)简析Python web框架FastAPI——一个比Flask和Tornada更高性能的API 框架 和 (进阶篇)Python web框架FastAPI——一个比Flask和Tornada更高性能的API 框架 。今天欢迎大家来到 FastAPI 系列分享的完结篇,本文主要是对于前面文章的补充和扩展。 当然这些功能在实际开发中也扮演者极其重要的角色。 1 中间件的使用 Flask 有 钩子函数,可以对某些方法进行装饰,在某些全局或者非全局的情况下,增添特定的功能。 同样在 FastAPI 中也存在着像钩子函数的东西,也就是中间件 Middleware了。 计算回调时间 # -*- coding: UTF-8 -*- import time from fastapi import FastAPI from starlette.requests import Request app = FastAPI() @app.middleware("http") async def add_process_time_header(request: Request, call_next): start_time = time.time() response = await call_next(request)

Starlette + asyncio.create_task() doesn't log error if task object is stored in instance variable [duplicate]

社会主义新天地 提交于 2020-03-04 18:43:23
问题 This question already has answers here : When asyncio task gets stored after creation, exceptions from task get muted (2 answers) Closed 13 days ago . Okay, this is very weird, but here goes - import asyncio from starlette.applications import Starlette class MyTasks: def __init__(self): self.task = None async def main(self): self.task = asyncio.create_task(self.hello()) async def hello(self): raise ValueError async def main(): await MyTasks().main() app = Starlette(on_startup=[main]) $

django

江枫思渺然 提交于 2020-02-27 20:06:42
aiodns 1.1.1 aiohttp 3.6.1 asn1crypto 0.24.0 async-timeout 3.0.1 attrs 19.1.0 bcrypt 3.1.7 blessings 1.7 bootstrap4 0.1.0 bpython 0.18 ccxt 1.18.524 certifi 2019.9.11 cffi 1.12.3 chardet 3.0.4 Click 7.0 cryptography 2.7 curtsies 0.3.1 Django 2.1 django-appconf 1.0.3 django-axes 4.5.4 django-bootstrap4 0.0.7 django-encrypted-model-fields 0.5.8 django-ipware 2.1.0 django-widget-tweaks 1.4.3 greenlet 0.4.15 gunicorn 19.9.0 h11 0.9.0 httptools 0.0.13 idna 2.6 jega 0.1 krakenex 2.1.0 multidict 4.5.2 numpy 1.17.2 pandas 0.23.4 paramiko 2.4.1 pdfkit 0.6.1 Pillow 7.0.0 pip 20.0.2 pipenv 2018.11.26

uvicorn与gunicorn/gunicorn+meinheld性能对比

回眸只為那壹抹淺笑 提交于 2019-12-15 18:30:55
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Running: uvicorn asgiproj.asgi:application -b 127.0.0.1:8001 [erm@fezzan ~]$ wrk -d20s -t10 -c200 http://127.0.0.1:8001/asgi/ Running 20s test @ http://127.0.0.1:8001/asgi/ 10 threads and 200 connections Thread Stats Avg Stdev Max +/- Stdev Latency 28.68ms 10.16ms 69.46ms 76.20% Req/Sec 700.81 130.10 4.79k 82.43% 139697 requests in 20.10s, 19.32MB read Socket errors: connect 0, read 78, write 0, timeout 0 Requests/sec: 6949.09 Transfer/sec: 0.96MB Running: gunicorn asgiproj.wsgi:application -b 127.0.0.1:8001 [erm@fezzan ~]$ wrk -d20s -t10 -c200 http://127.0