|
| 1 | +import inspect |
1 | 2 | import re |
2 | 3 | import sys |
3 | 4 | from importlib import import_module |
@@ -175,19 +176,30 @@ def check(self, loop): |
175 | 176 | raise AdevConfigError('app_factory "{.app_factory_name}" is not callable or an ' |
176 | 177 | 'instance of aiohttp.web.Application'.format(self)) |
177 | 178 |
|
| 179 | + loop.run_until_complete(self._startup_cleanup(loop)) |
| 180 | + |
| 181 | + def load_app(self, loop): |
178 | 182 | if isinstance(self.app_factory, Application): |
179 | 183 | app = self.app_factory |
180 | 184 | else: |
181 | 185 | # app_factory should be a proper factory with signature (loop): -> Application |
182 | | - app = self.app_factory(loop) |
| 186 | + signature = inspect.signature(self.app_factory) |
| 187 | + if 'loop' in signature.parameters: |
| 188 | + app = self.app_factory(loop=loop) |
| 189 | + else: |
| 190 | + # loop argument missing, assume no arguments |
| 191 | + app = self.app_factory() |
| 192 | + |
183 | 193 | if not isinstance(app, Application): |
184 | 194 | raise AdevConfigError('app factory "{.app_factory_name}" returned "{.__class__.__name__}" not an ' |
185 | 195 | 'aiohttp.web.Application'.format(self, app)) |
186 | 196 |
|
187 | | - logger.debug('app "%s" successfully created', app) |
188 | | - loop.run_until_complete(self._startup_cleanup(app)) |
| 197 | + return app |
189 | 198 |
|
190 | | - async def _startup_cleanup(self, app): |
| 199 | + async def _startup_cleanup(self, loop): |
| 200 | + app = self.load_app(loop) |
| 201 | + app._set_loop(loop) |
| 202 | + logger.debug('app "%s" successfully created', app) |
191 | 203 | logger.debug('running app startup...') |
192 | 204 | await app.startup() |
193 | 205 | logger.debug('running app cleanup...') |
|
0 commit comments