1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-10 15:22:24 +01:00

dashboard: fix subprocesses blocking the event loop (#5772)

* dashboard: fix subprocesses blocking the event loop

- break apart the util module
- adds a new util to run subprocesses with asyncio

* take a list
This commit is contained in:
J. Nick Koston
2023-11-15 18:07:51 -06:00
committed by GitHub
parent 4e3170dc95
commit 3644853d38
9 changed files with 101 additions and 70 deletions

View File

@@ -31,13 +31,14 @@ import yaml
from tornado.log import access_log
from esphome import const, platformio_api, yaml_util
from esphome.helpers import get_bool_env, mkdir_p, run_system_command
from esphome.helpers import get_bool_env, mkdir_p
from esphome.storage_json import StorageJSON, ext_storage_path, trash_storage_path
from esphome.util import get_serial_ports, shlex_quote
from .core import DASHBOARD, list_dashboard_entries
from .entries import DashboardEntry
from .util import friendly_name_slugify
from .util.text import friendly_name_slugify
from .util.subprocess import async_run_system_command
_LOGGER = logging.getLogger(__name__)
@@ -522,7 +523,7 @@ class DownloadListRequestHandler(BaseHandler):
class DownloadBinaryRequestHandler(BaseHandler):
@authenticated
@bind_config
def get(self, configuration=None):
async def get(self, configuration=None):
compressed = self.get_argument("compressed", "0") == "1"
storage_path = ext_storage_path(configuration)
@@ -548,7 +549,7 @@ class DownloadBinaryRequestHandler(BaseHandler):
if not Path(path).is_file():
args = ["esphome", "idedata", settings.rel_path(configuration)]
rc, stdout, _ = run_system_command(*args)
rc, stdout, _ = await async_run_system_command(args)
if rc != 0:
self.send_error(404 if rc == 2 else 500)
@@ -902,7 +903,7 @@ SafeLoaderIgnoreUnknown.add_constructor(
class JsonConfigRequestHandler(BaseHandler):
@authenticated
@bind_config
def get(self, configuration=None):
async def get(self, configuration=None):
filename = settings.rel_path(configuration)
if not os.path.isfile(filename):
self.send_error(404)
@@ -910,7 +911,7 @@ class JsonConfigRequestHandler(BaseHandler):
args = ["esphome", "config", filename, "--show-secrets"]
rc, stdout, _ = run_system_command(*args)
rc, stdout, _ = await async_run_system_command(args)
if rc != 0:
self.send_error(422)