-
-
Notifications
You must be signed in to change notification settings - Fork 630
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
Async broken on v1.4.0 with FastAPI app #1874
Comments
Additional info, adding some logging I get the following error message on reloading the tab after clicking the buttons.
|
Thanks for the bug report, @zilch42! This a serious one. 🫤 But it seems to be a duplicate of #1870, and I think I found a fix and a workaround: #1870 (comment). |
Thanks @falkoschindler I've tried adding the workaround from #1870 (full code below) but it doesn't seem to solve this issue. from nicegui import ui, run, app
from nicegui.nicegui import _shutdown, _startup
from fastapi import FastAPI
import asyncio
import requests
async def async_task():
ui.notify('Asynchronous task started')
await asyncio.sleep(5)
ui.notify('Asynchronous task finished')
async def handle_click():
URL = 'https://httpbin.org/delay/1'
response = await run.io_bound(requests.get, URL, timeout=3)
ui.notify(f'Downloaded {len(response.content)} bytes')
@ui.page('/')
def home():
ui.button('start async task', on_click=async_task)
ui.button('Download', on_click=handle_click)
# works on 1.3.18, broken on 1.4.0
FastApp = FastAPI()
ui.run_with(FastApp)
app.on_event('startup')(_startup)
app.on_event('shutdown')(_shutdown)
if __name__ == '__main__':
print('Please start with "uvicorn main:FastApp --reload --log-level info --port 8000"')
# works on 1.3.18 and 1.4.0
# ui.run() Still don't get any |
@zilch42 In your case the app is called FastApp.on_event('startup')(_startup)
FastApp.on_event('shutdown')(_shutdown) |
Oh that was silly of me. Thank you. I thought it was app from |
Description
The following async functions work on 1.3.18 but do nothing on 1.4.0 (no notification, no error, no indication something is happening) when using FastAPI. They work fine if using the normal
ui.run()
.I guess it's related to #1849 but I didn't think there was a breaking change (I'm not using
@on_event("startup")
and@on_event("shutdown")
explicitly).The text was updated successfully, but these errors were encountered: