Comments (8)
NiceGUI is using uvicorn as a server which has still problems with graceful shutdowns (see encode/uvicorn#1103 for example). We need to think about this a bit. My not so graceful suggestion would be to start NiceGUI without reload=True
, launch a new process on exit and just live with exceptions printed on the console:
from nicegui import ui
import sys
def apply():
print('Starting main system in seperate process')
# subprocess.Popen(['python3', 'my_main_system.py'])
sys.exit(0)
ui.label('Configuration')
ui.label('... your config UI here ...')
ui.button('Apply', on_click=apply)
ui.run(reload=False)
from nicegui.
ui.shutdown
Correction: app.shutdown
from nicegui.
Yes, it would be great to have something like
from nicegui import ui
ui.label('Your configurtion UI...')
def quit():
... # How?
ui.button('Quit', on_click=quit)
ui.run(reload=False)
print('Do something else...')
It's a pity that uvicorn.run()
starts a server
that's not exposed to the outside, but would have a server.shutdown()
method.
Monkey-patching uvicorn.run()
(or simply copying its content over into our run.py
) would be an option. But due to the many configuration options thats more than 120 lines of code and doesn't feel quite right.
from nicegui.
The solution multiprocessing.Process
-Solution described in https://stackoverflow.com/a/70980373/364388 looked promising. But the whole app needs to be pickled... which does not work in NiceGUI:
AttributeError: Can't pickle local object 'CustomView.use.<locals>.<lambda>'
I've pushed the code to branch #83-Process.
from nicegui.
I've got a first idea working on #83-ui.shutdown.
The main idea stems from @falkoschindler #83 (comment). We could simply create the uvicorn server object inside nicegui instead of relying on the uvicorn.run
helper. The API may look as following:
ui.button('Quit', on_click=ui.shutdown)
But there is still work to be done. For example auto-reloading is still broken.
from nicegui.
I tried to add more code from uvicorn.run
: 501323d
Now the app starts with reload=False
and reload=True
. But with auto-reload the "Quit" button does not work, because the spawned process has no nicegui.globals.server
set. That's only the case in the parent process. But maybe we don't need reloading anyway. We could simply raise an exception that ui.shutdown
does not work with reload=True
.
Another issue: When the socket connection is lost due to the server being shut down, the JustPy frontend asks for confirmation to reload the page. This makes no sense and should be avoided.
from nicegui.
Nice! After moving ui.shutdown into the lifecycle module the reload-confirmation dialog is gone.
from nicegui.
The ui.shutdown()
method is now available in v0.8.16
from nicegui.
Related Issues (20)
- Nginx subpath example doesn't redirect correctly when navigating to subpage with trailing slash
- ui.plotly chart randomly collapses / shrinks HOT 2
- Leaflet always uses the full width
- Troubles while periodically updating the 3D scene HOT 6
- Native mode and resizability of the window HOT 4
- Text in input and select components is not aligned to each other HOT 5
- ui.input validation will remain space after it's value was corrected HOT 3
- Select fails to change value on first try. HOT 6
- `run_method` and `getElement` return inconsistent types of elements HOT 1
- Using `copy.deepcopy` on storage causes data loss. HOT 4
- Problem for passing parameter to handler function for dynamic added `ul.html` , `ui.botton`, maybe others. HOT 2
- KeyError in `ui.log` after client disconnected HOT 4
- AG Grids inside hidden tabs don't get mounted HOT 3
- pyinstaller and cpu_bound issue HOT 6
- Leaflet: map flickers between centers after flyTo HOT 1
- Change to MS-Windows style windows is not possible? HOT 2
- 2-way bindings backward direction does not work anymore HOT 1
- Not able to clear input anymore HOT 1
- Accessibility issue with hidden connection warning HOT 3
- Autocomplete for `ui.input` not working on mobile HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nicegui.