Refactor doom-num-cpus
Adds error handling.
This commit is contained in:
parent
a50db6291b
commit
b426e21ef1
1 changed files with 20 additions and 10 deletions
|
@ -48,13 +48,23 @@ Warning: freezes indefinitely on any stdin prompt."
|
||||||
Tries to be portable. Returns 1 if cannot be determined."
|
Tries to be portable. Returns 1 if cannot be determined."
|
||||||
(or doom--num-cpus
|
(or doom--num-cpus
|
||||||
(setq doom--num-cpus
|
(setq doom--num-cpus
|
||||||
(max
|
(let ((cpus
|
||||||
1 (cond ((eq 'windows-nt system-type)
|
(cond ((getenv "NUMBER_OF_PROCESSORS"))
|
||||||
(or (ignore-errors
|
((executable-find "nproc")
|
||||||
(string-to-number (getenv "NUMBER_OF_PROCESSORS")))
|
(doom-call-process "nproc"))
|
||||||
1))
|
((executable-find "sysctl")
|
||||||
((executable-find "nproc")
|
(doom-call-process "sysctl" "-n" "hw.ncpu")))))
|
||||||
(string-to-number (cdr (doom-call-process "nproc"))))
|
(max
|
||||||
((and IS-MAC (executable-find "sysctl"))
|
1 (or (cl-typecase cpus
|
||||||
(string-to-number (cdr (doom-call-process "sysctl" "-n" "hw.ncpu"))))
|
(string
|
||||||
(t 1))))))
|
(condition-case _
|
||||||
|
(string-to-number cpus)
|
||||||
|
(wrong-type-argument
|
||||||
|
(user-error "NUMBER_OF_PROCESSORS contains an invalid value: %S"
|
||||||
|
cpus))))
|
||||||
|
(consp
|
||||||
|
(if (zerop (car cpus))
|
||||||
|
(string-to-number (cdr cpus))
|
||||||
|
(user-error "Failed to look up number of processors, because:\n\n%s"
|
||||||
|
(cdr cpus)))))
|
||||||
|
1))))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue