Skip to navigation
Setup an aiohttp webapp with gunicorn
23.07.18
example 1. import argparse import asyncio import logging import sys import jinja2 import aiohttp_jinja2 import sqlalchemy as sa import aiohttp_autoreload import utils import dbs import jinja2 import aiohttp_jinja2 from aiohttp import web from middlewares import setup_middlewares from routes import setup_routes from utils import TRAFARET from trafaret_config import commandline from helpers import strings,dates async def main(): debug = True ap = argparse.ArgumentParser(description='API Server') commandline.standard_argparse_options(ap,default_config='../config/sapi.yaml') options = ap.parse_args([]) config = commandline.config_from_options(options, TRAFARET) app = web.Application() app['config'] = config app['name'] = 'SAPI' env = aiohttp_jinja2.setup(app,loader=jinja2.FileSystemLoader('templates')) env.filters['hexme'] = strings.hexme env.filters['today'] = dates.today setup_routes(app) setup_middlewares(app) if debug: aiohttp_autoreload.start() return app 2. run with gunicorn $: gunicorn main:main --bind 0.0.0.0:8080 --worker-class aiohttp.GunicornWebWorker
https://aiohttp-wsgi.readthedocs.io/en/stable/wsgi.html
Reply
Anonymous
Information Epoch 1732667208
Use lower case and keep it short.
Home
Notebook
Contact us