Can't set a non-default event loop when running `adev runserver`
vladiibine opened this issue · comments
This is the command that I'm running
adev runserver -v butler/app.py --app-factory create_app --pre-check
..And this is the traceback I get
Process Process-1:
Traceback (most recent call last):
File "/home/username/.pyenv/versions/3.6.3/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/home/username/.pyenv/versions/3.6.3/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/home/username/work/project/project-venv/lib/python3.6/site-packages/aiohttp_devtools/runserver/serve.py", line 127, in serve_main_app
loop=loop,
File "/home/username/work/project/project-venv/lib/python3.6/site-packages/aiohttp/web.py", line 250, in make_handler
self._set_loop(loop)
File "/home/username/work/project/project-venv/lib/python3.6/site-packages/aiohttp/web.py", line 128, in _set_loop
"web.Application instance initialized with different loop")
RuntimeError: web.Application instance initialized with different loop
The problem is that I am instantiating my app like this: app = aiohttp.web.Application(loop=uvloop)
.
I have no way of making this change the default ioloop policy before a default ioloop is being instantiated.
This is the function that's killing my buzz:
def serve_main_app(config: Config, tty_path: Optional[str], loop: asyncio.AbstractEventLoop=None):
with set_tty(tty_path):
setup_logging(config.verbose)
# THIS IS THE BUZZ-KILLING LINE
# If only this line was AFTER the current line - but that is circular and can't be done currently.
# However, if my factory function was loaded before this line was executed, then I'd be very happy :D
# That would give me the chance to do `asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())`
loop = loop or asyncio.get_event_loop()
app = config.load_app(loop)
modify_main_app(app, config)
loop.run_until_complete(check_port_open(config.main_port, loop))
handler = app.make_handler(
logger=dft_logger,
access_log_format='%r %s %b',
loop=loop,
)
Do you need help with this? I'd gladly import the factory function before retrieving the loop. That could probably make a few people happy.
Thanks!
What aiohttp version are you using and what version of aiohttp-devtools?
The loop
argument to Application
has been deprecated since at least 2.2.
Hi
I have seen indeed that the argument is deprecated, however even if I'd be calling web.Application()
with no loop
argument, I'd have the problem that I still wouldn't want to use the default event loop.
I created a PR for this. Please review it, and if it's fine, I'd be very happy if this was integrated and released in some time, at your own leisure :)
Thanks a lot for the cool library!