瀏覽代碼

socketio heartbeats depend on reconnect_timeout

Rodja Trappe 1 年之前
父節點
當前提交
5fbe811f68
共有 2 個文件被更改,包括 5 次插入1 次删除
  1. 1 1
      main.py
  2. 4 0
      nicegui/nicegui.py

+ 1 - 1
main.py

@@ -447,4 +447,4 @@ def status():
     return 'Ok'
 
 
-ui.run(uvicorn_reload_includes='*.py, *.css, *.html', reconnect_timeout=3.0)
+ui.run(uvicorn_reload_includes='*.py, *.css, *.html', reconnect_timeout=10.0)

+ 4 - 0
nicegui/nicegui.py

@@ -71,6 +71,10 @@ def get_component(key: str) -> FileResponse:
 
 @app.on_event('startup')
 def handle_startup(with_welcome_message: bool = True) -> None:
+    if globals.reconnect_timeout > 0:  # TODO in 1.4 we DEPRECATED a value of 0 and should remove this check
+        # NOTE ping interval and timeout need to be lower than the reconnect timeout, but can't be too low
+        globals.sio.eio.ping_interval = max(globals.reconnect_timeout * 0.8, 4)
+        globals.sio.eio.ping_timeout = max(globals.reconnect_timeout * 0.4, 2)
     if not globals.ui_run_has_been_called:
         raise RuntimeError('\n\n'
                            'You must call ui.run() to start the server.\n'