How to get uvicorn event loop?
See original GitHub issueI run uvicorn server programmatically:
if __name__ == '__main__':
uvicorn.run(
'app:app',
host='127.0.0.1',
port=8000,
log_level='info',
loop='asyncio'
)
How can I get the created asyncio loop to reuse it for aiogram bot?
I have bot.py
file for telegram bot and app.py
file for starlette application running on uvicorn. When I’m trying to call asyncio.get_running_loop()
in bot.py
I gets the error that says that there is no running event loops at this time.
Is it even able to create asyncio loop manually and pass it to uvicorn.run
function?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
How to use event loop created by uvicorn? - Stack Overflow
Basically you have to create your own event loop and pass it to uvicorn. import asyncio from uvicorn import Config, Server async def ......
Read more >Uvicorn
the event loop uvloop will be installed and used if possible. · uvloop is a fast, drop-in replacement of the built-in asyncio event...
Read more >ASGI Event Loop Gotcha - Rob Blackbourn
Event () , via a web page served by the Uvicorn ASGI server, using the bareASGI framework. import asyncio import urllib.parsefrom bareasgi import...
Read more >tiangolo/fastapi - Gitter
I'm using https://github.com/tiangolo/uvicorn-gunicorn-docker as the base ... time.sleep will block the event loop, you need await asyncio.sleep in an async ...
Read more >fastapi asyncio.run() cannot be called from a running event loop
from fastapi import FastAPI import uvicorn app = FastAPI() @app.get("/") async ... This is due to Jupyter already running an event loop, and...
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
I’ve actually find the solution by getting loop instance in
on_startup()
method of my Starlette application, but making user able to pass his loop instance can be a good impovement.