使用werkzeug或uvicorn在后台线程中启动WSGI或ASGI应用。
项目描述
⚙️ 服务器线程
使用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 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d89f80048b1c2ea311ab10665e955d8a075c7a823a06c80563714aff42c4ec12 |
|
MD5 | 7632997419fcb13014bfa1f1f9465f64 |
|
BLAKE2b-256 | 4b16b3a3e54dac1a557384aafef25edd1909586904937f72128eeadebfb15673 |
关闭
server_thread-0.2.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2b779e54ec96debadc72b9622f7365b191ed444a230b38bd31b89ea8b7166a38 |
|
MD5 | da657ddfd87d69359bb5dad8714790b6 |
|
BLAKE2b-256 | 6429454b1c597eb418f4f95499eabbb8d32c375c50043695fab456ea8a7e8c27 |