server.py 628 B

1234567891011121314151617181920212223
  1. import threading
  2. from time import sleep
  3. from nicegui import globals as nicegui_globals
  4. from nicegui import ui
  5. class Server():
  6. def start(self):
  7. '''Start the webserver in a separate thread. This is the equivalent of `ui.run()` in a normal script.'''
  8. self.thread = threading.Thread(target=ui.run, kwargs={'port': 3392, 'show': False, 'reload': False})
  9. self.thread.start()
  10. sleep(1)
  11. def stop(self):
  12. '''Stop the webserver.'''
  13. nicegui_globals.server.should_exit = True
  14. self.thread.join()
  15. @property
  16. def base_url(self):
  17. return 'http://localhost:3392'