Skip to content

Commit

Permalink
[build] Use os.sched_getaffinity only if available
Browse files Browse the repository at this point in the history
This change un-breaks the build in macOS and Windows environments, by
only calling the Python os.sched_getaffinity() function where it’s
available (which seems to be only on Linux) — and where it’s not
available, using multiprocessing.cpu_count() instead.

Otherwise, the build fails in macOS and Windows environment, because the
document/core/util/mathjax2katex.py program fails — and fails the build —
with a “module 'os' has no attribute 'sched_getaffinity'” message
(because os.sched_getaffinity(0) is hardcoded into the program).
  • Loading branch information
sideshowbarker committed Feb 15, 2024
1 parent 17cf849 commit 165f9f2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion document/core/util/mathjax2katex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: latin-1 -*-

import queue
import multiprocessing
import os
import re
import shelve
Expand Down Expand Up @@ -229,7 +230,8 @@ def Worker():
sys.stderr.write('.')

q = queue.Queue()
for i in range(len(os.sched_getaffinity(0))):
for i in range(len(os.sched_getaffinity(0)) if "sched_getaffinity" in dir(os)
else multiprocessing.cpu_count()):
t = threading.Thread(target=Worker)
t.daemon = True
t.start()
Expand Down

0 comments on commit 165f9f2

Please sign in to comment.