Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fork is not available on windows #28

Open
PanagiotisS opened this issue Nov 4, 2024 · 0 comments
Open

Fork is not available on windows #28

PanagiotisS opened this issue Nov 4, 2024 · 0 comments

Comments

@PanagiotisS
Copy link

Hello.

I have encountered the following error on windows,

ValueError: cannot find context for 'fork'

Fork (or forkserver) is not available on windows, https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods

The issue if from the following line

72bc089#diff-b3b1f4cc344f3013a1b743b1876cb3e6e9848d15aab3ffbb48067978419a1a1aR446-R451

def _set_multiprocessing_start_method() -> None:
    # this is currently required because the latest litestar uses a QueueListener logging handler
    if platform.system() in {"Darwin", "Windows"}:
        multiprocessing.set_start_method("fork", force=True)

If I change the following line to

-        multiprocessing.set_start_method("fork", force=True)
+        multiprocessing.set_start_method("spawn", force=True)

or even if I ignore the line completely (on Windows),

-    if platform.system() in {"Darwin", "Windows"}:
+    if platform.system() in {"Darwin"}:

it works fine.

Minimal example:

# app.py
from litestar import Controller, Litestar, get
from litestar.logging import LoggingConfig
from litestar_granian import GranianPlugin


class SampleController(Controller):
    @get(path="/sample")
    async def sample_route(self) -> dict[str, str]:
        """Sample Route."""
        return {"sample": "hello-world"}


logging_config = LoggingConfig(
    root={"level": "INFO", "handlers": ["queue_listener"]},
    formatters={
        "standard": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}
    },
    log_exceptions="always",
)
logger = logging_config.configure()()

app = Litestar(
    plugins=[GranianPlugin()],
    route_handlers=[SampleController],
    logging_config=logging_config,
)
# pyproject.toml
[project]
name = "test"
version = "1.0.0"
requires-python = "==3.12.*"

dependencies = [
    "litestar",
    "litestar-granian",
]

Versions:

  • python version: Python 3.12.6
  • windows 11
  • litestar: 2.12.1
  • litestar-granian: 0.7.1
  • granian: 1.6.3

P.S.
Regarding the comment,

# this is currently required because the latest litestar uses a QueueListener logging handler

I indeed had this problem after the commit e1f1485 and I had set this to True in my code, but I see this was changed back to True as a default.

Thank you.
Best wishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant