got Future <Future pending> attached to a different loop
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
def main():
uvicorn.run(app,host="0.0.0.0",port=8090,loop="asyncio")
loop = asyncio.get_event_loop()
def run():
loop.run_until_complete(main())
def keep_alive1():
t = threading.Thread(target=run)
t.start()
keep_alive1()
client.run('discord bot token')
Description
i was using discord client with fastapi i used another thread for running uvicorn. the bot worked fine but when i used the fastapi endpoints it gave me an error
RuntimeError: Task <Task pending name='Task-32' coro=<RequestResponseCycle.run_asgi() running at /opt/virtualenvs/python3/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py:369> cb=[set.discard()]> got Future <Future pending> attached to a different loop
the endpoint that gave me this error was asynchronous using mongodb module motor, other non asynchronous endpoints worked fine like the /docs.
when i removed the discord client with just the fastapi it still didnt worked with uvicorn.run() but did worked with the cmd command uvicorn main:app not sure why tho.
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.66.0
Python Version
3.9.4
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
python - Using queues results in asyncio exception "got Future ...
run() , so they use events.get_event_loop() . asyncio.run() creates a new loop, and futures created for the queue in one loop can't then...
Read more >Task got Future <Future pending> attached to a different loop
I'm trying to reproduce the simplest example with Python native module with async function exported and call it from Python. lib.rs: use ...
Read more >tiangolo/fastapi - Gitter
@david-e you're most likely hit by the infamous got Future <Future pending> attached to a different loop. well this is the case, if...
Read more >על השגיאה got Future attached to a different loop ב Python
על השגיאה got Future attached to a different loop ב Python ... <Task pending name='Task-4' coro=<download() running at post.py:6> cb=[_wait.<locals>.
Read more >Futures — Python 3.11.1 documentation
Return the event loop the Future object is bound to. New in version 3.7. This example creates a Future object, creates and schedules...
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 FreeTop 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
Top GitHub Comments
Yeah, that PR solves an issue that should never happen. 😃
thanks it worked, tho you should add a little note in the docs about the motor connector.