{"record":{"id":"b78518813d2516d4","repo":"pola-rs/polars","slug":"could-not-allocate-memory-for-cpuid-check","errorCode":null,"errorMessage":"could not allocate memory for CPUID check","messagePattern":"could not allocate memory for CPUID check","errorType":"exception","errorClass":"MemoryError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_cpu_check.py","lineNumber":176,"sourceCode":"            opc = _POSIX_64_OPC if _IS_64BIT else _CDECL_32_OPC\n\n        size = len(opc)\n        code = (ctypes.c_ubyte * size)(*opc)\n\n        if _IS_WINDOWS:\n            self.win.VirtualAlloc.restype = c_void_p\n            self.win.VirtualAlloc.argtypes = [\n                ctypes.c_void_p,\n                ctypes.c_size_t,\n                ctypes.c_ulong,\n                ctypes.c_ulong,\n            ]\n            self.addr = self.win.VirtualAlloc(\n                None, size, _MEM_COMMIT | _MEM_RESERVE, _PAGE_EXECUTE_READWRITE\n            )\n            if not self.addr:\n                msg = \"could not allocate memory for CPUID check\"\n                raise MemoryError(msg)\n            ctypes.memmove(self.addr, code, size)\n        else:\n            import mmap  # Only import if necessary.\n\n            # On some platforms PROT_WRITE + PROT_EXEC is forbidden, so we first\n            # only write and then mprotect into PROT_EXEC.\n            libc = _open_posix_libc()\n            mprotect = libc.mprotect\n            mprotect.argtypes = (ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int)\n            mprotect.restype = ctypes.c_int\n\n            self.mmap = mmap.mmap(\n                -1,\n                size,\n                mmap.MAP_PRIVATE | mmap.MAP_ANONYMOUS,\n                mmap.PROT_READ | mmap.PROT_WRITE,\n            )\n            self.addr = ctypes.addressof(ctypes.c_void_p.from_buffer(self.mmap))","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_cpu_check.py#L158-L194","documentation":"In `_cpu_check.py`, the CPUID feature-check class allocates executable memory to run a small CPUID stub (via `VirtualAlloc` on Windows or `mmap`/`mprotect` elsewhere). If the OS refuses the allocation, the constructor raises `MemoryError` with this message. It indicates the process could not obtain the executable memory it needs for the CPU capability probe.","triggerScenarios":"Constructing the CPUID check object on Windows when `VirtualAlloc(None, size, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE)` returns NULL — e.g. exhausted virtual address space, restrictive security policies, or low-memory conditions.","commonSituations":"Running polars import inside hardened containers/CI with RWX-memory restrictions; systems under severe memory pressure; 32-bit processes with fragmented address space.","solutions":["Free memory or increase the process/container memory limit, then retry the import.","Check security software (EDR/AV) or sandbox policies blocking PAGE_EXECUTE_READWRITE allocations and allowlist the process.","Run on a supported 64-bit platform/architecture, or use a polars build that skips the runtime CPU check."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    import polars as pl\nexcept MemoryError as e:\n    # increase memory limits / disable exec-memory restrictions\n    raise RuntimeError('insufficient memory or blocked RWX allocation for polars CPU check') from e","preventionTips":["Provision adequate memory for the container/process running polars.","Avoid hardened environments that forbid PAGE_EXECUTE_READWRITE allocations, or allowlist polars.","Prefer 64-bit Python builds to avoid address-space exhaustion."],"tags":["python","polars","memoryerror","cpu-check","windows"],"backgroundTag":"unsupported-platform","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}