dbrattli / aioreactive

Async/await reactive tools for Python 3.11+
MIT License
350 stars 24 forks source link

Error example autocomplete , web.Application instance initialized with different loop #32

Closed bueltan closed 1 year ago

bueltan commented 2 years ago

summarized Traceback. ... File "/home/denis/Documents/env_aioreactive/lib/python3.9/site-packages/aiohttp/web.py", line 321, in _run_app await runner.setup() File "/home/denis/Documents/env_aioreactive/lib/python3.9/site-packages/aiohttp/web_runner.py", line 279, in setup self._server = await self._make_server() File "/home/denis/Documents/env_aioreactive/lib/python3.9/site-packages/aiohttp/web_runner.py", line 373, in _make_server self._app._set_loop(loop) File "/home/denis/Documents/env_aioreactive/lib/python3.9/site-packages/aiohttp/web_app.py", line 223, in _set_loop raise RuntimeError( RuntimeError: web.Application instance initialized with different loop

Process finished with exit code 1

Packages Versions


aiohttp 3.8.1 aiohttp-jinja2 1.5 aioreactive 0.16.0 aiosignal 1.2.0 async-timeout 4.0.2 attrs 22.1.0 charset-normalizer 2.1.0 expression 2.2.0 frozenlist 1.3.0 idna 3.3 Jinja2 3.1.2 MarkupSafe 2.1.1 multidict 6.0.2 pip 21.3.1 setuptools 60.2.0 typing_extensions 4.3.0 wheel 0.37.1 yarl 1.7.2

bueltan commented 1 year ago

Fix this by removing the loop as an application parameter, also notice some problem with the version installed of "Expression" but leave this for other issue.


async def init(loop: AbstractEventLoop):
    port = os.environ.get("PORT", 8080)
    host = "localhost"
    app = web.Application(loop=loop)
    print("Starting server at port: %s" % port)
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader("."))
    app.router.add_static("/static", "static")
    app.router.add_get("/", index)
    app.router.add_get("/ws", websocket_handler)
    return app, host, port

def main():
    loop: AbstractEventLoop = asyncio.get_event_loop()
    app, host, port = loop.run_until_complete(init(loop))
    web.run_app(app, host=host, port=int(port))

to :

async def init():
    app = web.Application()
    print("Starting server at port: %s" % port)
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader("."))
    app.router.add_static("/static", "static")
    app.router.add_get("/", index)
    app.router.add_get("/ws", websocket_handler)
    return app

def main():
    port = os.environ.get("PORT", 5055)
    web.run_app(init(), host="localhost", port=int(port))