Unverified 提交 23f5877b authored 作者: Dan Foreman-Mackey's avatar Dan Foreman-Mackey 提交者: GitHub

Fixes ResourceWarnings on macOS (#38)

上级 e53c4879
......@@ -26,32 +26,14 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#
# This function was modified from the original code
# We can't use the multiprocessing module as it was included in python2.6
# and we support python 2.4
import os
import sys
import multiprocessing
def cpuCount():
"""
Returns the number of CPUs in the system
"""
if sys.platform == "win32":
try:
num = int(os.environ["NUMBER_OF_PROCESSORS"])
except (ValueError, KeyError):
num = -1
elif sys.platform == "darwin":
try:
num = int(os.popen("sysctl -n hw.ncpu").read())
except ValueError:
num = -1
else:
try:
num = os.sysconf("SC_NPROCESSORS_ONLN")
except (ValueError, OSError, AttributeError):
num = -1
return num
try:
return multiprocessing.cpu_count()
except NotImplementedError:
return -1
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论