Skip to content

Commit

Permalink
coroutine is allowed to return web.AppRunner (#5611)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Sviatoslav Sydorenko <sviat@redhat.com>
  • Loading branch information
3 people committed Oct 28, 2021
1 parent 00d5286 commit 9a1c862
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES/2988.feature
@@ -0,0 +1 @@
Added a ``GunicornWebWorker`` feature for extending the aiohttp server configuration by allowing the 'wsgi' coroutine to return ``web.AppRunner`` object.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -85,6 +85,7 @@ David Bibb
David Michael Brown
Denilson Amorim
Denis Matiychuk
Denis Moshensky
Dennis Kliban
Dima Veselov
Dimitar Dimitrov
Expand Down
28 changes: 19 additions & 9 deletions aiohttp/worker.py
Expand Up @@ -61,23 +61,33 @@ 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 9a1c862

Please sign in to comment.