[Windows 11] psutil.process_iter() is 10x slower when running from non-admin account than when running from ADMIN/elevated account
Summary
- OS: Windows 11
- Architecture: 64bit
- Psutil version: 5.9.8
- Python version: 3.12.1
- Type: performance
Description
Running the following Python code from a non-admin Windows user account, takes about 400ms.
And when running the same code from a the same Windows user account, but through an ADMIN/elevated cmd.exe command prompt, it takes about 38-40ms, which is 10x faster.
The total exec time does not seem to be influenced by whether the process searched for, is currently running or not. Also, when the process searched for is running, it's always only 1 instance of it, so no multiple processes of the same name.
import psutil
p: psutil.Process | None = next(
(p for p in psutil.process_iter(attrs=["name"]) if p.name() == "dbengprx.exe"),
None)
The code above is invoked indirectly, via Uvicorn ASGI web application server (configured with only 1 worker) and FastAPI web api framework.
Same machine, same Virtual Mem usage, same list or processes between the two cases. About 220 processes showing in TaskMgr / tasklist, in both cases.
There is something that makes psutil's Process item generator go 10x slower in non-admin mode, than in admin mode.
Thank you.