Repository: reflex-dev/reflex
Pull request: opt for powershell as opposed to wmic
Fixes #4198


Problem statement:
wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv
**Describe the bug**
The command `wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv` failed with error: Command 'wmic cpu get
addresswidth,caption,manufacturer /FORMAT:csv' returned non-zero exit status 1.. This will return None.

AND infinity reloading local server!


**Specifics (please complete the following information):**
 - Python Version: 3.12
 - Reflex Version: 0.6.3
 - OS: Windows 11
 - Browser (Optional): Chrome
 
**Additional context**
After create a new project and first start server it's work, but after why I remake the code server are not starting , just say in terminal "WARNING:  WatchFiles detected changes in 'FistApp\main.py'. Reloading..."
after this my terminal are crashing, not working. I need to close him and open then.

Hints from issue discussion:
<p><a href="https://linear.app/reflex-dev/issue/ENG-3962/wmic-cpu-get-addresswidthcaptionmanufacturer-formatcsv">ENG-3962 wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv</a></p>
is this a regression from 0.6.2?
> [ENG-3962 wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv](https://linear.app/reflex-dev/issue/ENG-3962/wmic-cpu-get-addresswidthcaptionmanufacturer-formatcsv)

I for Russia. Site doesn't work( 
Do u have alternative?
 
> is this a regression from 0.6.2?

idk, but I can say 6 month ago I dont take this problem.
> Do u have alternative?

That's an internal issue tracker for the team, it's not public. Any comments here will end up over there and we'll triage it for an upcoming sprint.
Can you try running:

```bash
wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv
```

in the command line?

otherwise, the infinite hot-reload isn't because of this, but because of something else (unsure as we don't have any clue towards that), can you try running with:

```bash
reflex run --loglevel prod
```
Not sure if this helps (I'm new to reflex and web development, in general. But the minimal config demo on a windows notebook also creates the error message:

`Ungültiges XSL-Format (oder) Dateiname.
The command 'wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv' failed with error: Command 'wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv' returned non-zero exit 
status 44210.. This will return None.
`
I.e. I didn't change anything in this repo. Does this help?
when you just run `wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv` in the terminal, is there an error message that comes up?
Yes, it says:

Ungültiges XSL-Format (oder) Dateiname.

Which essentially translates into "Invalid XLS-format or filename"

interesting, seeing this http://www.thegeekblog.co.uk/quick-tips/2013/10/8/fix-the-invalid-xsl-format-or-file-name-error.html

which suggests this may be a problem with the `/format` switch in conjunction with a locale other than the one used when installing windows...

does this error prevent you from running the app? or does it just appear when you start up?

Commit message: mkdir of parents

Patch to review:
diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py
index 8afa706be5b..d3d8bd6ab49 100644
--- a/reflex/utils/prerequisites.py
+++ b/reflex/utils/prerequisites.py
@@ -1925,24 +1925,23 @@ def format_address_width(address_width: str | None) -> int | None:
         return None
 
 
-@functools.lru_cache(maxsize=None)
-def get_cpu_info() -> CpuInfo | None:
-    """Get the CPU info of the underlining host.
+def _load_cpu_info() -> CpuInfo | None:
+    """Load the CPU info of the underlining host.
 
     Returns:
-         The CPU info.
+        The CPU info.
     """
     platform_os = platform.system()
     cpuinfo = {}
     try:
         if platform_os == "Windows":
-            cmd = "wmic cpu get addresswidth,caption,manufacturer /FORMAT:csv"
+            cmd = 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object AddressWidth,Manufacturer,Name | ConvertTo-Json"'
             output = processes.execute_command_and_return_output(cmd)
             if output:
-                val = output.splitlines()[-1].split(",")[1:]
-                cpuinfo["manufacturer_id"] = val[2]
-                cpuinfo["model_name"] = val[1].split("Family")[0].strip()
-                cpuinfo["address_width"] = format_address_width(val[0])
+                cpu_data = json.loads(output)
+                cpuinfo["address_width"] = cpu_data["AddressWidth"]
+                cpuinfo["manufacturer_id"] = cpu_data["Manufacturer"]
+                cpuinfo["model_name"] = cpu_data["Name"]
         elif platform_os == "Linux":
             output = processes.execute_command_and_return_output("lscpu")
             if output:
@@ -1981,6 +1980,23 @@ def get_cpu_info() -> CpuInfo | None:
     )
 
 
+@functools.lru_cache(maxsize=None)
+def get_cpu_info() -> CpuInfo | None:
+    """Get the CPU info of the underlining host.
+
+    Returns:
+        The CPU info.
+    """
+    cpu_info_file = environment.REFLEX_DIR.get() / "cpu_info.json"
+    if cpu_info_file.exists() and (cpu_info := json.loads(cpu_info_file.read_text())):
+        return CpuInfo(**cpu_info)
+    cpu_info = _load_cpu_info()
+    if cpu_info:
+        cpu_info_file.parent.mkdir(parents=True, exist_ok=True)
+        cpu_info_file.write_text(json.dumps(dataclasses.asdict(cpu_info)))
+    return cpu_info
+
+
 @functools.lru_cache(maxsize=None)
 def is_windows_bun_supported() -> bool:
     """Check whether the underlining host running windows qualifies to run bun.


Code review comments:
diff_hunk: @@ -1925,12 +1925,11 @@ def format_address_width(address_width: str | None) -> int | None:
         return None
 
 
-@functools.lru_cache(maxsize=None)
-def get_cpu_info() -> CpuInfo | None:
-    """Get the CPU info of the underlining host.
+def _load_cpu_info() -> CpuInfo | None:
+    """Load the CPU info of the underlining host.
path: reflex/utils/prerequisites.py
text: @user1:
seems like this should be _retrieve_cpu_info

```suggestion
def _load_cpu_info() -> CpuInfo | None:
    """Load the CPU info of the underlying host.
```