pmb.qemu: add ncpus fallback (MR 2252)

According to the type hints for os.cpu_count(), it might return None...
To be safe, add a warning and a fallback in this case (though it seems
incredibly unlikely this would ever be hit)

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-04-04 03:34:48 +02:00 committed by Oliver Smith
parent 7ed08e74d3
commit 233cbdadeb
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -117,6 +117,9 @@ def command_qemu(args: PmbArgs, arch, img_path, img_path_2nd=None):
raise RuntimeError("failed to find the proper vmlinuz path")
ncpus = os.cpu_count()
if not ncpus:
logging.warning("Couldn't get cpu count, defaulting to 4")
ncpus = 4
# QEMU mach-virt's max CPU count is 8, limit it so it will work correctly
# on systems with more than 8 CPUs