app: replace refrences to ioloop with eventloop
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
d224536552
commit
8a3ff7a54a
|
@ -9,7 +9,6 @@ import os
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
import traceback
|
import traceback
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
@ -22,7 +21,6 @@ from tornado.escape import url_unescape
|
||||||
from tornado.routing import Rule, PathMatches, AnyMatches
|
from tornado.routing import Rule, PathMatches, AnyMatches
|
||||||
from tornado.http1connection import HTTP1Connection
|
from tornado.http1connection import HTTP1Connection
|
||||||
from tornado.log import access_log
|
from tornado.log import access_log
|
||||||
from tornado.ioloop import IOLoop
|
|
||||||
from utils import ServerError
|
from utils import ServerError
|
||||||
from websockets import WebRequest, WebsocketManager, WebSocket
|
from websockets import WebRequest, WebsocketManager, WebSocket
|
||||||
from streaming_form_data import StreamingFormDataParser
|
from streaming_form_data import StreamingFormDataParser
|
||||||
|
@ -43,6 +41,7 @@ from typing import (
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from tornado.httpserver import HTTPServer
|
from tornado.httpserver import HTTPServer
|
||||||
from moonraker import Server
|
from moonraker import Server
|
||||||
|
from eventloop import EventLoop
|
||||||
from confighelper import ConfigHelper
|
from confighelper import ConfigHelper
|
||||||
from websockets import APITransport
|
from websockets import APITransport
|
||||||
from components.file_manager.file_manager import FileManager
|
from components.file_manager.file_manager import FileManager
|
||||||
|
@ -691,7 +690,9 @@ class FileRequestHandler(AuthorizedFileHandler):
|
||||||
self.set_header("Content-Length", content_length)
|
self.set_header("Content-Length", content_length)
|
||||||
|
|
||||||
if include_body:
|
if include_body:
|
||||||
content = self.get_content_nonblock(self.absolute_path, start, end)
|
evt_loop = self.server.get_event_loop()
|
||||||
|
content = self.get_content_nonblock(
|
||||||
|
evt_loop, self.absolute_path, start, end)
|
||||||
async for chunk in content:
|
async for chunk in content:
|
||||||
try:
|
try:
|
||||||
self.write(chunk)
|
self.write(chunk)
|
||||||
|
@ -709,10 +710,12 @@ class FileRequestHandler(AuthorizedFileHandler):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_content_nonblock(
|
async def get_content_nonblock(
|
||||||
cls, abspath: str, start: Optional[int] = None,
|
cls,
|
||||||
|
evt_loop: EventLoop,
|
||||||
|
abspath: str,
|
||||||
|
start: Optional[int] = None,
|
||||||
end: Optional[int] = None
|
end: Optional[int] = None
|
||||||
) -> AsyncGenerator[bytes, None]:
|
) -> AsyncGenerator[bytes, None]:
|
||||||
ioloop = IOLoop.current()
|
|
||||||
with open(abspath, "rb") as file:
|
with open(abspath, "rb") as file:
|
||||||
if start is not None:
|
if start is not None:
|
||||||
file.seek(start)
|
file.seek(start)
|
||||||
|
@ -724,9 +727,7 @@ class FileRequestHandler(AuthorizedFileHandler):
|
||||||
chunk_size = 64 * 1024
|
chunk_size = 64 * 1024
|
||||||
if remaining is not None and remaining < chunk_size:
|
if remaining is not None and remaining < chunk_size:
|
||||||
chunk_size = remaining
|
chunk_size = remaining
|
||||||
with ThreadPoolExecutor(max_workers=1) as tpe:
|
chunk = await evt_loop.run_in_thread(file.read, chunk_size)
|
||||||
chunk = await ioloop.run_in_executor(
|
|
||||||
tpe, file.read, chunk_size)
|
|
||||||
if chunk:
|
if chunk:
|
||||||
if remaining is not None:
|
if remaining is not None:
|
||||||
remaining -= len(chunk)
|
remaining -= len(chunk)
|
||||||
|
@ -770,9 +771,8 @@ class FileUploadHandler(AuthorizedRequestHandler):
|
||||||
|
|
||||||
async def data_received(self, chunk: bytes) -> None:
|
async def data_received(self, chunk: bytes) -> None:
|
||||||
if self.request.method == "POST":
|
if self.request.method == "POST":
|
||||||
with ThreadPoolExecutor(max_workers=1) as tpe:
|
evt_loop = self.server.get_event_loop()
|
||||||
await IOLoop.current().run_in_executor(
|
await evt_loop.run_in_thread(self._parser.data_received, chunk)
|
||||||
tpe, self._parser.data_received, chunk)
|
|
||||||
|
|
||||||
async def post(self) -> None:
|
async def post(self) -> None:
|
||||||
form_args = {}
|
form_args = {}
|
||||||
|
|
Loading…
Reference in New Issue