Sanic Server WorkerManager refactor (#2499)
Co-authored-by: Néstor Pérez <25409753+prryplatypus@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import json
|
||||
|
||||
from sanic import Sanic, text
|
||||
from sanic.application.constants import Mode
|
||||
from sanic.config import Config
|
||||
from sanic.log import LOGGING_CONFIG_DEFAULTS, logger
|
||||
|
||||
|
||||
@@ -16,7 +18,7 @@ async def handler(request):
|
||||
return text(request.ip)
|
||||
|
||||
|
||||
@app.before_server_start
|
||||
@app.main_process_start
|
||||
async def app_info_dump(app: Sanic, _):
|
||||
app_data = {
|
||||
"access_log": app.config.ACCESS_LOG,
|
||||
@@ -27,6 +29,13 @@ async def app_info_dump(app: Sanic, _):
|
||||
logger.info(json.dumps(app_data))
|
||||
|
||||
|
||||
@app.main_process_stop
|
||||
async def app_cleanup(app: Sanic, _):
|
||||
app.state.auto_reload = False
|
||||
app.state.mode = Mode.PRODUCTION
|
||||
app.config = Config()
|
||||
|
||||
|
||||
@app.after_server_start
|
||||
async def shutdown(app: Sanic, _):
|
||||
app.stop()
|
||||
@@ -38,8 +47,8 @@ def create_app():
|
||||
|
||||
def create_app_with_args(args):
|
||||
try:
|
||||
print(f"foo={args.foo}")
|
||||
logger.info(f"foo={args.foo}")
|
||||
except AttributeError:
|
||||
print(f"module={args.module}")
|
||||
logger.info(f"module={args.module}")
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user