#๐Ÿ”’ future attached to different loop error

4 messages ยท Page 1 of 1 (latest)

wispy venture
#

how can i fix this error?

Traceback (most recent call last):
  File "/var/task/discohook/handler.py", line 125, in _handler
    raise e
  File "/var/task/discohook/handler.py", line 117, in _handler
    await component(interaction)
  File "/var/task/src/screens/explore.py", line 145, in place_button
    (grid, configs), defer_response, refresh_at, local_id = await get_grid(interaction, True) # force refresh
  File "/var/task/src/utils/helpers.py", line 111, in get_grid
    grid_data, refresh_at = await fetch_task
  File "/var/task/src/utils/helpers.py", line 87, in fetch
    await lock.acquire()
  File "/var/lang/lib/python3.9/asyncio/locks.py", line 120, in acquire
    await fut
RuntimeError: Task <Task pending name='Task-129' coro=<get_grid.<locals>.fetch() running at /var/task/src/utils/helpers.py:87> cb=[_wait.<locals>._on_completion() at /var/lang/lib/python3.9/asyncio/tasks.py:509]> got Future <Future pending> attached to a different loop

this is my code

      loop = asyncio.get_event_loop()
      defer_task = loop.create_task(defer())
      fetch_task = loop.create_task(fetch())

      done, pending = await asyncio.wait((defer_task, fetch_task), return_when = asyncio.FIRST_COMPLETED)
      
      if defer_task in done: # 2 seconds passed
        defer_response = await interaction.response.defer()
      else:
        defer_task.cancel()
      
      if asyncio.get_event_loop() == fetch_task._loop:
        grid_data, refresh_at = await fetch_task
      else:
        grid_data, refresh_at = fetch_task._loop.run_until_complete(fetch_task)
pallid vectorBOT
#

@wispy venture

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

pallid vectorBOT
#

@wispy venture

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.