Skip to content

Commit

Permalink
Preview process: Replaced Process with Thread if running on Python 3.12+
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitorac committed Jun 16, 2024
1 parent 69b3f45 commit 1453956
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/esbonio/esbonio/lsp/sphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import logging
import pathlib
import platform
import sys
import traceback
import typing
import warnings
from functools import partial
from multiprocessing import Process
from multiprocessing import Queue
from threading import Thread
from typing import IO
from typing import Any
from typing import Dict
Expand Down Expand Up @@ -48,6 +50,12 @@

from .line_number_transform import LineNumberTransform

# Use a Thread as a preview server instead of Process for Python 3.12+
# Usable since Thread and Process shares the same API
PreviewExecutor = Process
if sys.version_info.major >= 3 and sys.version_info.minor >= 12:
PreviewExecutor = Thread

__all__ = [
"InitializationOptions",
"MissingConfigError",
Expand Down Expand Up @@ -434,14 +442,14 @@ def preview(self, options: Dict[str, Any]) -> Dict[str, Any]:
server = make_preview_server(self.app.outdir) # type: ignore[arg-type]
self.preview_port = server.server_port

self.preview_process = Process(target=server.serve_forever, daemon=True)
self.preview_process = PreviewExecutor(target=server.serve_forever, daemon=True)
self.preview_process.start()

if not self.preview_process and not IS_LINUX:
self.logger.debug("Starting preview server")

q: Queue = Queue()
self.preview_process = Process(
self.preview_process = PreviewExecutor(
target=start_preview_server, args=(q, self.app.outdir), daemon=True
)
self.preview_process.start()
Expand Down

0 comments on commit 1453956

Please sign in to comment.