Skip to content

Commit

Permalink
coroutine is allowed to return web.AppRunner
Browse files Browse the repository at this point in the history
These changes allow the configuration of web.AppRunner object inside application code. This makes possible to use custom configs of Aiohttp server (like 'max_line_size' parameters setup) in pair with Gunicorn.
Associated issue: aio-libs#2988 (reference)
  • Loading branch information
loven-doo committed Apr 12, 2021
1 parent 930e698 commit 174d928
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions aiohttp/worker.py
Expand Up @@ -61,23 +61,31 @@ def run(self) -> None:
sys.exit(self.exit_code)

async def _run(self) -> None:
runner = None
if isinstance(self.wsgi, Application):
app = self.wsgi
elif asyncio.iscoroutinefunction(self.wsgi):
app = await self.wsgi()
wsgi = await self.wsgi()
if isinstance(wsgi, web.AppRunner):
runner = wsgi
app = runner.app
else:
app = wsgi
else:
raise RuntimeError(
"wsgi app should be either Application or "
"async function returning Application, got {}".format(self.wsgi)
)
access_log = self.log.access_log if self.cfg.accesslog else None
runner = web.AppRunner(
app,
logger=self.log,
keepalive_timeout=self.cfg.keepalive,
access_log=access_log,
access_log_format=self._get_valid_log_format(self.cfg.access_log_format),
)

if runner is None:
access_log = self.log.access_log if self.cfg.accesslog else None
runner = web.AppRunner(
app,
logger=self.log,
keepalive_timeout=self.cfg.keepalive,
access_log=access_log,
access_log_format=self._get_valid_log_format(self.cfg.access_log_format),
)
await runner.setup()

ctx = self._create_ssl_context(self.cfg) if self.cfg.is_ssl else None
Expand Down

0 comments on commit 174d928

Please sign in to comment.