app: fix blocking I/O
Open and close static files to be read using the default thread pool executor. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
27466984df
commit
790d77756e
|
@ -46,6 +46,7 @@ if TYPE_CHECKING:
|
||||||
from confighelper import ConfigHelper
|
from confighelper import ConfigHelper
|
||||||
from klippy_connection import KlippyConnection as Klippy
|
from klippy_connection import KlippyConnection as Klippy
|
||||||
from components.file_manager.file_manager import FileManager
|
from components.file_manager.file_manager import FileManager
|
||||||
|
from io import BufferedReader
|
||||||
import components.authorization
|
import components.authorization
|
||||||
MessageDelgate = Optional[tornado.httputil.HTTPMessageDelegate]
|
MessageDelgate = Optional[tornado.httputil.HTTPMessageDelegate]
|
||||||
AuthComp = Optional[components.authorization.Authorization]
|
AuthComp = Optional[components.authorization.Authorization]
|
||||||
|
@ -778,7 +779,8 @@ class FileRequestHandler(AuthorizedFileHandler):
|
||||||
start: Optional[int] = None,
|
start: Optional[int] = None,
|
||||||
end: Optional[int] = None
|
end: Optional[int] = None
|
||||||
) -> AsyncGenerator[bytes, None]:
|
) -> AsyncGenerator[bytes, None]:
|
||||||
with open(abspath, "rb") as file:
|
file: BufferedReader = await evt_loop.run_in_thread(open, abspath, "rb")
|
||||||
|
try:
|
||||||
if start is not None:
|
if start is not None:
|
||||||
file.seek(start)
|
file.seek(start)
|
||||||
if end is not None:
|
if end is not None:
|
||||||
|
@ -798,6 +800,8 @@ class FileRequestHandler(AuthorizedFileHandler):
|
||||||
if remaining is not None:
|
if remaining is not None:
|
||||||
assert remaining == 0
|
assert remaining == 0
|
||||||
return
|
return
|
||||||
|
finally:
|
||||||
|
await evt_loop.run_in_thread(file.close)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_cached_version(cls, abs_path: str) -> Optional[str]:
|
def _get_cached_version(cls, abs_path: str) -> Optional[str]:
|
||||||
|
|
Loading…
Reference in New Issue