Description
Bug report
Bug description:
From Python 3.12, probably since #89545 was implemented, the invocation of functions from platform
modules takes a multiple of 5 seconds if the user has no permissions to perform WMI queries. It can be reproduced by connecting to a Windows machine using SSH and executing a Python script from cmd or ps. Access to WMI for remote sessions is turned off by default but this probably can be achieved also by removing permissions using wmimgmt.msc
application.
For example, the execution of the system
function in Python 3.12:
user@WIN16 c:\Python3.12>python.exe -m timeit -s "import platform" -n 1 -r 1 "platform.system()"
1 loop, best of 1: 10.2 sec per loop
and the same in Python 3.11:
user@WIN16 c:\Python3.11>python.exe -m timeit -s "import platform" -n 1 -r 1 "platform.system()"
1 loop, best of 1: 18.1 msec per loop
(timeit
used with -n 1 -r 1
to avoid using cache in the platform module. When results get cached then of course it works fast).
The delay comes from de33df2#diff-cb1ba6039236dca71c97ea898f2798c60262c30614192862259889f839e4d503R323 which takes 5 seconds and raises OSError
: [WinError -2147217405] Windows Error 0x80041003
. platform.system
apparently calls it twice. This applies to all functions from the module that makes WMI queries.
Windows version used for tests:
Edition: Windows Server 2016 Standard
Version: 1607
OS Build: 14393.6452
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
- gh-112278: reduce time cost for platform module when no permission to WMI on Windows #112658
- gh-112278: add a new event to simulate COM init timeout in _wmi module #112878
- gh-112278: add retry in test_wmi.py #113154
- gh-112278: Improve error handling in wmi module and tests #117818
- [3.12] gh-112278: Improve error handling in wmi module and tests (GH-117818) #117899