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

Error got Future <Future pending> attached to a different loop #19

Open
mahenzon opened this issue Feb 23, 2023 · 1 comment
Open

Error got Future <Future pending> attached to a different loop #19

mahenzon opened this issue Feb 23, 2023 · 1 comment

Comments

@mahenzon
Copy link
Owner

mahenzon commented Feb 23, 2023

Example

from aiohttp import web
from aioalice import Dispatcher, get_new_configured_app


WEBHOOK_URL_PATH = '/my-alice-webhook/'  # webhook endpoint

WEBAPP_HOST = 'localhost'
WEBAPP_PORT = 3001

dp = Dispatcher()


@dp.request_handler()
async def handle_all_requests(alice_request):
    return alice_request.response('Привет этому миру!')


if __name__ == '__main__':
    app = get_new_configured_app(dispatcher=dp, path=WEBHOOK_URL_PATH)
    web.run_app(app, host=WEBAPP_HOST, port=WEBAPP_PORT)

Error

======== Running on http://localhost:3001 ========
(Press CTRL+C to quit)
Error handling request
Traceback (most recent call last):
  File "/user/simple-alice/venv/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/simple-alice/venv/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/user/simple-alice/venv/lib/python3.11/site-packages/aiohttp/web_urldispatcher.py", line 954, in _iter
    resp = await method()
           ^^^^^^^^^^^^^^
  File "/user/simple-alice/venv/lib/python3.11/site-packages/aioalice/dispatcher/webhook.py", line 183, in post
    result = await self.process_request(request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/simple-alice/venv/lib/python3.11/site-packages/aioalice/dispatcher/webhook.py", line 101, in process_request
    await waiter
RuntimeError: Task <Task pending name='Task-5' coro=<RequestHandler._handle_request() running at /user/simple-alice/venv/lib/python3.11/site-packages/aiohttp/web_protocol.py:433> cb=[Task.task_wakeup()]> got Future <Future pending> attached to a different loop
@mahenzon
Copy link
Owner Author

mahenzon commented Feb 23, 2023

Вариант решения: передать текущий event loop в web.run_app:

if __name__ == '__main__':
    app = get_new_configured_app(dispatcher=dp, path=WEBHOOK_URL_PATH)
    web.run_app(app, host=WEBAPP_HOST, port=WEBAPP_PORT, loop=dp.loop)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant