RuntimeError: got Future <Future pending> attached to a different loop
See original GitHub issueDescription
Getting the following error when running an async flow in orion server or cloud
RuntimeError: Task <Task pending name='anyio.from_thread.BlockingPortal._call_func' coro=<BlockingPortal._call_func() running at /Users/noam.cohen/Library/Caches/pypoetry/virtualenvs/finance-lGLYToYy-py3.9/lib/python3.9/site-packages/anyio/from_thread.py:219> cb=[TaskGroup._spawn.<locals>.task_done() at /Users/noam.cohen/Library/Caches/pypoetry/virtualenvs/finance-lGLYToYy-py3.9/lib/python3.9/site-packages/anyio/_backends/_asyncio.py:726]> got Future <Future pending> attached to a different loop
Reproduction
import asyncio
from dotenv import load_dotenv
from prefect import task, flow
@task
async def print_values(values):
for value in values:
await asyncio.sleep(1) # yield
print(value, end=" ")
@task
def get_numbers():
return [1, 2]
@flow(name='test-flow')
async def dummy_flow():
numbers = get_numbers()
await print_values(numbers) # runs immediately
coros = [print_values("abcd"), print_values("6789")]
# asynchronously gather the tasks
await asyncio.gather(*coros)
if __name__ == '__main__':
load_dotenv()
asyncio.run(dummy_flow())
Environment
prefect 2.08b
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
python - Using queues results in asyncio exception "got Future ...
run() creates a new loop, and futures created for the queue in one loop can't then be used in the other. Create your...
Read more >Task got Future <Future pending> attached to a different loop
The error you see is saying that the main() coroutine is running on the event loop started by asyncio.run , but it is...
Read more >ืขื ืืฉืืืื got Future attached to a different loop ื Python
ืขื ืืฉืืืื got Future attached to a different loop ื Python ... defined at post.py:5> exception=RuntimeError("Task <Task pending name='Task-4'ย ...
Read more >ASGI Event Loop Gotcha - Rob Blackbourn
ASGI Event Loop Gotcha. I've shed many tears with the following exception: got Future <Future pending> attached to a different loop.
Read more >tiangolo/fastapi - Gitter
I want to create two models that reference one another: ... My error is always "got Future <Future pending> attached to a different...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This does not reproduce on the latest release.
Ahh gotcha, next time if you could link to that discussion, it would help, I canโt remember all that ๐
Could you use one of the solutions I suggested, and if that works close the issue here? I understand what you mean, but I think the mechanics here work well enough and not sure if spending more time on optimizing this is worth it as opposed to other really cool things we can do in 2.0 instead