mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
dashboard: set nodelay on the websocket to avoid a delay seeing log messages (#5802)
This commit is contained in:
parent
2076db1ccd
commit
1762204b00
1 changed files with 16 additions and 1 deletions
|
@ -27,6 +27,7 @@ import tornado.process
|
||||||
import tornado.queues
|
import tornado.queues
|
||||||
import tornado.web
|
import tornado.web
|
||||||
import tornado.websocket
|
import tornado.websocket
|
||||||
|
import tornado.httputil
|
||||||
import yaml
|
import yaml
|
||||||
from tornado.log import access_log
|
from tornado.log import access_log
|
||||||
|
|
||||||
|
@ -136,7 +137,15 @@ def websocket_method(name):
|
||||||
|
|
||||||
@websocket_class
|
@websocket_class
|
||||||
class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||||
def __init__(self, application, request, **kwargs):
|
"""Base class for ESPHome websocket commands."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
application: tornado.web.Application,
|
||||||
|
request: tornado.httputil.HTTPServerRequest,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the websocket."""
|
||||||
super().__init__(application, request, **kwargs)
|
super().__init__(application, request, **kwargs)
|
||||||
self._proc = None
|
self._proc = None
|
||||||
self._queue = None
|
self._queue = None
|
||||||
|
@ -145,6 +154,12 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||||
# use Popen() with a reading thread instead
|
# use Popen() with a reading thread instead
|
||||||
self._use_popen = os.name == "nt"
|
self._use_popen = os.name == "nt"
|
||||||
|
|
||||||
|
def open(self, *args: str, **kwargs: str) -> None:
|
||||||
|
"""Handle new WebSocket connection."""
|
||||||
|
# Ensure messages from the subprocess are sent immediately
|
||||||
|
# to avoid a 200-500ms delay when nodelay is not set.
|
||||||
|
self.set_nodelay(True)
|
||||||
|
|
||||||
@authenticated
|
@authenticated
|
||||||
async def on_message( # pylint: disable=invalid-overridden-method
|
async def on_message( # pylint: disable=invalid-overridden-method
|
||||||
self, message: str
|
self, message: str
|
||||||
|
|
Loading…
Reference in a new issue