跳转到主要内容

使用werkzeug或uvicorn在后台线程中启动WSGI或ASGI应用。

项目描述

⚙️ 服务器线程

Tests codecov PyPI conda

使用werkzeug或uvicorn在后台线程中启动WSGI或ASGI应用。

此应用是为localtileserver创建的,为如何在Jupyter笔记本中可视化数据如何作为后台线程启动图像瓦片服务器提供了基础。

虽然这个库可能不是广泛适用的,但它对我创建的几个需要后台服务的Python包很有用。

🚀 使用

使用ServerThread与任何WSGI或ASGI应用。

首先创建一个应用(这可以是一个Flask应用或如以下简单的应用)

# Create some WSGI Application
from werkzeug import Request, Response

@Request.application
def app(request):
    return Response("howdy", 200)

然后使用ServerThread类启动应用

import requests
from server_thread import ServerThread

# Launch app in a background thread
server = ServerThread(app)

# Perform requests against the server without blocking
requests.get(f"http://{server.host}:{server.port}/").raise_for_status()

⬇️ 安装

使用server-thread开始创建需要后台WSGIApplication的应用。

🐍 使用conda安装

Conda使跨平台管理server-thread的依赖变得相当容易,这是推荐的安装方法

conda install -c conda-forge server-thread

🎡 使用pip安装

如果您喜欢pip,则可以从PyPI安装: https://pypi.ac.cn/project/server-thread/

pip install server-thread

💭 反馈

请在讨论板上分享您的想法和问题。如果您想报告任何错误或提出功能请求,请打开一个问题。

如果在提交错误报告,请分享一个scooby 报告

import server_thread
print(server_thread.Report())

🚀 示例

使用server-thread与常用微框架的最小示例。

💨 FastAPI

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def root():
    return {"message": "Howdy!"}


server = ServerThread(app)
requests.get(f"http://{server.host}:{server.port}/").json()

⚗️ Flask

from flask import Flask

app = Flask("testapp")


@app.route("/")
def howdy():
    return {"message": "Howdy!"}


server = ServerThread(app)
requests.get(f"http://{server.host}:{server.port}/").json()

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

server-thread-0.2.0.tar.gz (7.2 kB 查看哈希值)

上传时间

构建分布

server_thread-0.2.0-py3-none-any.whl (8.5 kB 查看哈希值)

上传时间 Python 3

支持