Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GunicornWebWorker subclasses can config AppRunner #4720

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/2988.feature
@@ -0,0 +1,2 @@
Allow `GunicornWebWorker` subclasses to configure its `ApplicationRunner` by introducing the
`GunicornWebWorker._get_application_runner_instance` method.
19 changes: 12 additions & 7 deletions aiohttp/worker.py
Expand Up @@ -73,13 +73,7 @@ async def _run(self) -> None:
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))
runner = self._get_application_runner_instance(app)
await runner.setup()

ctx = self._create_ssl_context(self.cfg) if self.cfg.is_ssl else None
Expand Down Expand Up @@ -207,6 +201,17 @@ def _get_valid_log_format(self, source_format: str) -> str:
else:
return source_format

def _get_application_runner_instance(self, app, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method should be documented and type hinted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How **kwargs are used? I see it is always an empty dict.

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),
**kwargs)
return runner


class GunicornUVLoopWebWorker(GunicornWebWorker):

Expand Down