mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-12-16 00:05:48 -07:00
Require Eventlet for Engine runtime
This commit is contained in:
@@ -9,6 +9,7 @@ error log) to align with the project's operational practices.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import importlib.util
|
||||||
import logging
|
import logging
|
||||||
import ssl
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
@@ -16,27 +17,31 @@ from dataclasses import dataclass
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Mapping, Optional, Sequence, Tuple
|
from typing import Any, Mapping, Optional, Sequence, Tuple
|
||||||
|
|
||||||
try: # pragma: no-cover - optional dependency when running without eventlet
|
|
||||||
import eventlet # type: ignore
|
def _require_dependency(module: str, friendly_name: str) -> None:
|
||||||
except Exception: # pragma: no-cover - fall back to threading mode
|
if importlib.util.find_spec(module) is None: # pragma: no cover - import check
|
||||||
eventlet = None # type: ignore[assignment]
|
raise RuntimeError(
|
||||||
logging.getLogger(__name__).warning(
|
f"{friendly_name} (Python module '{module}') is required for the Borealis Engine runtime. "
|
||||||
"Eventlet is not available; Engine will run Socket.IO in threading mode."
|
"Install the packaged dependencies by running Borealis.ps1 or ensure the module is present in the active environment."
|
||||||
)
|
)
|
||||||
else: # pragma: no-cover - monkey patch only when eventlet is present
|
|
||||||
eventlet.monkey_patch(thread=False)
|
|
||||||
|
|
||||||
from flask import Flask, request
|
|
||||||
from flask_cors import CORS
|
|
||||||
from flask_socketio import SocketIO
|
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
||||||
|
|
||||||
if eventlet:
|
_require_dependency("eventlet", "Eventlet")
|
||||||
try: # pragma: no-cover - defensive import mirroring the legacy runtime.
|
_require_dependency("flask", "Flask")
|
||||||
from eventlet.wsgi import HttpProtocol # type: ignore
|
_require_dependency("flask_socketio", "Flask-SocketIO")
|
||||||
except Exception: # pragma: no-cover - the Engine should still operate without it.
|
|
||||||
HttpProtocol = None # type: ignore[assignment]
|
import eventlet # type: ignore # noqa: E402 # pragma: no cover - import guarded above
|
||||||
else:
|
from eventlet import wsgi as eventlet_wsgi # type: ignore # noqa: E402 # pragma: no cover
|
||||||
|
|
||||||
|
from flask import Flask, request # noqa: E402
|
||||||
|
from flask_cors import CORS # noqa: E402
|
||||||
|
from flask_socketio import SocketIO # noqa: E402
|
||||||
|
from werkzeug.middleware.proxy_fix import ProxyFix # noqa: E402
|
||||||
|
|
||||||
|
eventlet.monkey_patch(thread=False) # pragma: no cover - aligns with legacy runtime
|
||||||
|
|
||||||
|
HttpProtocol = getattr(eventlet_wsgi, "HttpProtocol", None)
|
||||||
|
if HttpProtocol is not None: # pragma: no branch - attribute exists in supported versions
|
||||||
_original_handle_one_request = HttpProtocol.handle_one_request
|
_original_handle_one_request = HttpProtocol.handle_one_request
|
||||||
|
|
||||||
def _quiet_tls_http_mismatch(self): # type: ignore[override]
|
def _quiet_tls_http_mismatch(self): # type: ignore[override]
|
||||||
@@ -78,10 +83,8 @@ if eventlet:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
HttpProtocol.handle_one_request = _quiet_tls_http_mismatch # type: ignore[assignment]
|
HttpProtocol.handle_one_request = _quiet_tls_http_mismatch # type: ignore[assignment]
|
||||||
else:
|
|
||||||
HttpProtocol = None # type: ignore[assignment]
|
|
||||||
|
|
||||||
_SOCKETIO_ASYNC_MODE = "eventlet" if eventlet else "threading"
|
_SOCKETIO_ASYNC_MODE = "eventlet"
|
||||||
|
|
||||||
|
|
||||||
# Ensure the legacy ``Modules`` package is importable when running from the
|
# Ensure the legacy ``Modules`` package is importable when running from the
|
||||||
|
|||||||
Reference in New Issue
Block a user