Python 3.6.0: 'os' 模块没有 'sched_getaffinity' 方法

Python 3.6.0: 'os' module does not have 'sched_getaffinity' method

我正在尝试按照 Why does multiprocessing use only a single core after I import numpy? 中的建议,使用 'os.sched_getaffinity' 方法检查我的脚本使用的核心数。但是当我 运行

import os
os.sched_getaffinity(0)

我明白了

AttributeError                            
Traceback (most recent call last) <ipython-input-1-895d9c252fd1> in <module>()
1 import os
----> 2 os.sched_getaffinity(0)
AttributeError: module 'os' has no attribute 'sched_getaffinity'

这里出了什么问题? 'os' 模块中的其他标准方法似乎有效。我正在 运行ning Anaconda 4.3.0 和 Python 3.6.0。 Mac 和 Linux 我都试过了。检查和更改任务相关性的任何替代方法?

文档说 "They are only available on some Unix platforms." 我想您的平台不是这些功能集所支持的平台之一。您可以通过输入

查看提供的内容
>>> import os
>>> print(dir(os))

该功能在我的 Debian Linux 机器上确实存在,但在 Windows 和 OSX 上也不存在。我不知道为什么它不在您的 Linux 盒子上。也许你的 Linux 太老了?

还有一个简单的 google for "python process affinity" 给出了几种选择