我已经看到,gunicorn提供了服务器钩子,我们可以用它来连接各种服务器事件,我在超级玉米中寻找同样的东西,因为它是以gunicorn为灵感的,但是超级玉米文档在这个问题上没有任何帮助,而且我还没有找到实现这个的人。
hyperconr.config.py
import multiprocessing as mp
import os
print( (mp.cpu_count() * 2) + 1)
accesslog = "-"
backlog = 500
bind = "0.0.0.0:8000"
statsd_host = os.environ.get("STASD_HOST")
workers = 3
max_requests = 2"""
This module is the entry point for the API.
This will contain all of the middleware and routes and database initialization
"""
from starlette.applications import Starlette
from starlette.routing import Route
# from sample_project import HealthCheckAPI
from src.health_check import HealthCheckAPI
routes = [
Route(f"/health-check", HealthCheckAPI)
]
app = Starlette(debug=True, routes=routes)
# app = AsyncioWSGIMiddleware(app)
if __name__ == "__main__":
from hypercorn.config import Config
config = Config()
config.bind = ["localhost:8077"]
config.debug = True
import asyncio
from hypercorn.asyncio import serve
asyncio.run(serve(app, config)) hypercorn -c file:config/hypercorn.config.py src.application:app下面是带有服务器钩子的gunicorn服务器的示例配置。
import multiprocessing as mp
import os
print( (mp.cpu_count() * 2) + 1)
accesslog = "-"
backlog = 500
bind = "0.0.0.0:8000"
statsd_host = os.environ.get("STASD_HOST")
workers = 3
max_requests = 2
def on_starting(server):
# register some variables here
print(server)
print("Starting Flask application")
def on_exit(server):
# perform some clean up tasks here using variables from the application
print("Shutting down Flask application")
def worker_exit(server, worker):
print("Worker exiting")
print(worker)
def nworkers_changed(server, new_value, old_value):
print("n worker",new_value)发布于 2022-11-01 20:59:39
超级玉米目前没有任何服务器钩子。然而,on_starting和on_exit被ASGI寿命事件所容纳。当使用Starlette时,这些是on_startup和on_shutdown 事件。
https://stackoverflow.com/questions/74271934
复制相似问题