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

落花浮王杯 提交于 2019-12-12 13:15:10

问题


I am trying to check the number of cores my script is using with 'os.sched_getaffinity' method as suggested in Why does multiprocessing use only a single core after I import numpy?. But when I run

import os
os.sched_getaffinity(0)

I get

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'

What is going wrong here? Other standard methods from the 'os' module seems to work. I am running Anaconda 4.3.0 with Python 3.6.0. I tried on both Mac and Linux. Any alternative ways to check and change the task affinity?


回答1:


The docs say "They are only available on some Unix platforms." I guess your platform isn't one of the supported ones for these set of functions. You can check what's provided by typing

>>> import os
>>> print(dir(os))

The function does exist on my Debian Linux box, but it is absent on Windows and OSX as well. I don't know why it's not there on your Linux box. Perhaps your Linux is too old?

Also a simple google for "python process affinity" gives several alternatives



来源:https://stackoverflow.com/questions/42538153/python-3-6-0-os-module-does-not-have-sched-getaffinity-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!