本文整理汇总了Python中aiohttp.web.run_app方法的典型用法代码示例。如果您正苦于以下问题:Python web.run_app方法的具体用法?Python web.run_app怎么用?Python web.run_app使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.web
的用法示例。
在下文中一共展示了web.run_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_app
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def run_app(port: int, endpoints: List[Endpoint], spec: str, framework: str) -> None:
if spec == "graphql":
app = _graphql.create_app()
app.run(port=port)
else:
if endpoints is not None:
prepared_endpoints = tuple(endpoint.name for endpoint in endpoints)
else:
prepared_endpoints = tuple(endpoint.name for endpoint in Endpoint)
version = {"openapi2": OpenAPIVersion("2.0"), "openapi3": OpenAPIVersion("3.0"),}[spec]
if framework == "aiohttp":
app = _aiohttp.create_openapi_app(prepared_endpoints, version)
web.run_app(app, port=port)
elif framework == "flask":
app = _flask.create_openapi_app(prepared_endpoints, version)
app.run(port=port)
示例2: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main(global_delay, local_delay, concurrency):
global global_sleep, local_sleep, semaphore, index
global_sleep = global_delay
local_sleep = local_delay
semaphore = asyncio.Semaphore(concurrency)
print('Global delay =', global_delay)
print('Local delay =', local_delay)
print('Max. concurrency =', concurrency)
print('Building inverted index...')
index = build_index()
app = web.Application()
app.router.add_get('/', usage)
app.router.add_get('/index/{word}', index_for)
app.router.add_get('/name/{char}', char_name)
print('Listening on port', PORT)
web.run_app(app, port=PORT)
示例3: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
router = SwaggerRouter(
swagger_ui='/swagger/',
search_dirs=[BASE],
)
app = web.Application(
router=router,
middlewares=[jsonify],
)
router.set_cors(app, domains='*', headers=(
(hdrs.ACCESS_CONTROL_EXPOSE_HEADERS, hdrs.AUTHORIZATION),
))
# Include our specifications in a router,
# is now available in the swagger-ui to the address http://localhost:8080/swagger/?spec=v1
router.include(
spec='swagger.yaml',
operationId_mapping=opmap,
name='v1', # name to access in swagger-ui
)
web.run_app(app)
示例4: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
app = web.Application()
s = SwaggerDocs(
app,
swagger_ui_settings=SwaggerUiSettings(
path="/docs",
layout="BaseLayout",
deepLinking=False,
displayOperationId=True,
defaultModelsExpandDepth=5,
defaultModelExpandDepth=5,
defaultModelRendering="model",
displayRequestDuration=True,
docExpansion="list",
filter=True,
showExtensions=True,
showCommonExtensions=True,
supportedSubmitMethods=["get"],
validatorUrl=None,
withCredentials=True,
),
)
s.add_routes([web.get("/", handler, allow_head=True)])
web.run_app(app)
示例5: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
app = web.Application()
s = SwaggerFile(
app,
spec_file="petstore.yaml",
swagger_ui_settings=SwaggerUiSettings(path="/docs"),
)
s.add_routes(
[
web.get("/pets", get_all_pets),
web.get("/pets/{pet_id}", get_one_pet),
web.delete("/pets/{pet_id}", delete_one_pet),
web.post("/pets", create_pet),
]
)
app["storage"] = {}
web.run_app(app)
示例6: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
app = web.Application()
s = SwaggerDocs(
app,
title="Swagger Petstore",
version="1.0.0",
components="components.yaml",
swagger_ui_settings=SwaggerUiSettings(path="/docs"),
)
s.add_routes(
[
web.get("/pets", get_all_pets),
web.get("/pets/{pet_id}", get_one_pet),
web.delete("/pets/{pet_id}", delete_one_pet),
web.post("/pets", create_pet),
]
)
app["storage"] = {}
web.run_app(app)
示例7: run
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def run(self, host, port):
def reg(mine, target):
assert isinstance(mine, Iterable)
for i in mine:
assert i, asyncio.Future
async def dummy(_raw_app):
await i()
target.append(dummy)
reg(self.on_startup, self._raw_app.on_startup)
reg(self.on_shutdown, self._raw_app.on_shutdown)
reg(self.on_cleanup, self._raw_app.on_cleanup)
self._prepare()
web.run_app(host=host, port=port, app=self._raw_app)
示例8: start
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def start():
parser = argparse.ArgumentParser()
parser.add_argument('--port', type=int, default=8420)
parser.add_argument('--from-scratch', action='store_true')
args = parser.parse_args()
if not args.from_scratch:
store.try_load_from_disk()
# Listen on both IPv4 and IPv6
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('::', args.port))
logger = logging.getLogger('aiohttp.access')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
web.run_app(app, sock=sock, access_log=logger)
示例9: run
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def run(self, port=8000):
"""Runs the web interface."""
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.app = web.Application(middlewares=[IndexMiddleware()], loop=self.loop)
self.app.event_queue = asyncio.Queue()
self.app.image_encode_settings = {'format': 'png'}
self.app.wss = []
self.app.task_process_events = self.loop.create_task(process_events(self.app))
self.app.router.add_route('GET', '/websocket', handle_websocket)
self.app.router.add_static('/', STATIC_PATH)
try:
web.run_app(self.app, port=port, shutdown_timeout=1, handle_signals=False)
except KeyboardInterrupt:
pass
示例10: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
"""Create connection and start web server."""
args = config()
conn = StaticConnection(
(args.my_verkey, args.my_sigkey),
their_vk=args.their_verkey,
endpoint=args.endpoint,
)
bmc = BasicMessageCounter()
conn.route_module(bmc)
async def handle(request):
""" aiohttp handle POST. """
await conn.handle(await request.read())
raise web.HTTPAccepted()
app = web.Application()
app.add_routes([web.post('/', handle)])
web.run_app(app, port=args.port)
示例11: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--redis-use-sentinel', action='store_true')
parser.add_argument('--sentinels', type=str)
parser.add_argument('--redis-host', type=str, default='localhost')
parser.add_argument('--no-uvloop', action='store_true')
parser.add_argument('--host', type=str, default='localhost')
parser.add_argument('--port', type=int, default=8080)
args = parser.parse_args()
app = web.Application()
app[REDIS] = {
SENTINEL: args.redis_use_sentinel,
SENTINELS: args.sentinels,
HOST: args.redis_host
}
app.on_startup.append(initialize_client_session)
app.on_startup.append(initialize_keystore)
app.on_cleanup.append(close_keystore)
app.on_cleanup.append(close_client_session_connection)
app.router.add_routes(routes)
if not args.no_uvloop:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
web.run_app(app, host=args.host, port=args.port)
示例12: run_server
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def run_server(host, port, endpoint, keystore, passcode, log, debug):
try:
response = requests.options(endpoint)
response.raise_for_status()
except requests.exceptions.ConnectionError:
print("Unable to connect to Thor-Restful server.")
return
print(make_version())
print("Listening on %s:%s" % (host, port))
thor.set_endpoint(endpoint)
if keystore == "":
thor.set_accounts(solo())
else:
thor.set_accounts(_keystore(keystore, passcode))
app = web.Application()
app.router.add_post("/", lambda r: handle(r, log, debug))
app.router.add_options("/", lambda r: web.Response(headers=res_headers))
web.run_app(app, host=host, port=port)
示例13: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
logging.basicConfig()
app = web.Application()
app.add_routes([
web.post('/graphql', handle_graphql),
])
app['graphql-endpoint'] = AsyncGraphQLEndpoint(
Engine(AsyncIOExecutor()), QUERY_GRAPH, MUTATION_GRAPH,
)
web.run_app(app)
示例14: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
log.info("Service node initializing")
app = create_app(asyncio.get_event_loop())
# run the app
port = int(config.get("sn_port"))
log.info(f"run_app on port: {port}")
run_app(app, port=port)
示例15: main
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import run_app [as 别名]
def main():
log.info("datanode start")
app = create_app(asyncio.get_event_loop())
# run the app
port = int(config.get("dn_port"))
log.info(f"run_app on port: {port}")
run_app(app, port=port)