GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Try to avoid invoking a new process to determine the Windows version in the platform module · Issue #129294 · python/cpython

Try to avoid invoking a new process to determine the Windows version in the platform module #129294

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Try to avoid invoking a new process to determine the Windows version in the platform module#129294
Copy link
Labels
OS-windowsperformancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@tomergert
tomergert
opened on Jan 25, 2025
Issue body actions

Feature or enhancement

Proposal:

In Lib/platform.py, there's a code aimed to determine the Windows version python runs in.

    for cmd in ('ver', 'command /c ver', 'cmd /c ver'):
        try:
            info = subprocess.check_output(cmd,
                                           stdin=subprocess.DEVNULL,
                                           stderr=subprocess.DEVNULL,
                                           text=True,
                                           encoding="locale",
                                           shell=True)

As much as I understand, one shouldn't invoke whole new process just to question what OS version he runs at.

so just before invoking cmd.exe, we will try to question winapi directly.

# Load ntdll.dll and call RtlGetVersion
    ntdll = ctypes.WinDLL("ntdll")
    rtl_get_version = ntdll.RtlGetVersion
    rtl_get_version(ctypes.byref(os_version))

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-129294: use winapi to determine win version before invoking cmd.exe #129295
Reacted by garoto

Activity

  1. tomergert
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jan 25, 2025
  2. hugovk
    added
    OS-windows
    on Jan 25, 2025
  3. encukou
    added
    performancePerformance or resource usagePerformance or resource usage
    on Jan 27, 2025
  4. zooba commented on Jan 27, 2025

    @zooba
    zooba
    on Jan 27, 2025
    Member
    More actions

    This is already fallback code for if WMI doesn't work, and GetVersionEx is already provided by sys.getwindowsversion.

    I don't think there's anything to change here.

  5. tomergert commented on Jan 28, 2025

    @tomergert
    tomergert
    on Jan 28, 2025
    Author
    More actions

    This is already fallback code for if WMI doesn't work, and GetVersionEx is already provided by sys.getwindowsversion.

    I don't think there's anything to change here.

    Thank you,. I addressed your comment in the PR
    #129295 (comment)

  6. zware commented on Jul 18, 2026

    @zware
    zware
    on Jul 18, 2026
    Member
    More actions

    In agreement with Steve, I'm going to close this issue. We may be at the point that we can remove the subprocess-based fallback entirely, but being the fallback fallback I'm not sure it's worth a change. Either way it's not a pressing concern, or a performance issue.

  7. zware
    closed this as not plannedon Jul 18, 2026
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

    OS-windowsperformancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.