首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >超玉米服务器钩子

超玉米服务器钩子
EN

Stack Overflow用户
提问于 2022-11-01 05:38:11
回答 1查看 37关注 0票数 0

我已经看到,gunicorn提供了服务器钩子,我们可以用它来连接各种服务器事件,我在超级玉米中寻找同样的东西,因为它是以gunicorn为灵感的,但是超级玉米文档在这个问题上没有任何帮助,而且我还没有找到实现这个的人。

hyperconr.config.py

代码语言:javascript
复制
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
代码语言:javascript
复制
"""
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))
代码语言:javascript
复制
 hypercorn -c file:config/hypercorn.config.py  src.application:app

下面是带有服务器钩子的gunicorn服务器的示例配置。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-01 20:59:39

超级玉米目前没有任何服务器钩子。然而,on_starting和on_exit被ASGI寿命事件所容纳。当使用Starlette时,这些是on_startup和on_shutdown 事件

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74271934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档