Skip to content

[FEATURE] Name the missing Visual C++ runtime when greenlet cannot load #697

Description

@stickerdaniel

Feature Description

On Windows the server can exit before it starts, with nothing that points at why:

ImportError: DLL load failed while importing _greenlet: The specified module could not be found.

Turn that into a message naming what is missing and where it comes from, and record it in the troubleshooting sections of the README.

Use Case

Reported in #688, and independently by the same user against another project that ships this server as a channel. Both landed on pinning greenlet<3.3 as the fix, which is the wrong medicine: the wheel is fine, it gained a system dependency.

greenlet moved its Windows builds from Appveyor to GitHub Actions in 3.3.1 and lost the GREENLET_STATIC_RUNTIME flag on the way, so _greenlet.pyd links the C++ runtime dynamically now. Import tables of the published cp312-win_amd64 wheels:

release imports
3.2.4 KERNEL32.dll, python312.dll
3.3.0 KERNEL32.dll, python312.dll
3.3.1 through 3.5.4 plus MSVCP140.dll, VCRUNTIME140.dll, VCRUNTIME140_1.dll

MSVCP140.dll comes with the Visual C++ redistributable and no Python distribution ships it. The python.org installer and the python-build-standalone builds uv uses both carry vcruntime140.dll and vcruntime140_1.dll and stop there, so a uvx user is more exposed than most.

We never call greenlet. patchright imports it unconditionally from _impl/_connection.py, on the async-only path too, so it loads in every run and a failure there stops the server before anything of ours executes.

Fixed upstream in python-greenlet/greenlet#525 / python-greenlet/greenlet#526, which does not retire this: the affected wheels stay on PyPI for good, and any resolver landing on one reproduces the failure.

Suggested Approach

A probe in the package __init__, which is the only place both entry paths reach before cli_main pulls in patchright. Windows only, and free on the path that matters because patchright imports the same module moments later. Match on DLL load failed, which CPython formats itself and is English on every install, and re-raise anything else untouched so a merely absent greenlet is not handed advice about a redistributable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions