Python 3.6.0:“ os”模块没有“ sched_getaffinity”方法 [英] Python 3.6.0: 'os' module does not have 'sched_getaffinity' method

查看:1306
本文介绍了Python 3.6.0:“ os”模块没有“ sched_getaffinity”方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照为什么在导入numpy后多处理仅使用单个内核?。但是当我运行

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)

我得到

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模块中的其他标准方法似乎可行。我正在使用Python 3.6.0运行Anaconda 4.3.0。我在Mac和Linux上都尝试过。还有其他检查和更改任务关联性的方法吗?

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?

推荐答案

文档说:它们仅在某些Unix平台上可用。我猜您的平台不是这些功能集所支持的平台之一。您可以通过键入

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))

该功能确实存在于我的Debian Linux机器上,但是不存在在Windows和OSX上也是如此。我不知道为什么Linux盒中没有它。也许您的Linux版本太旧了?

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?

另外,一个简单的 python进程相似性 google也提供了几种选择

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

这篇关于Python 3.6.0:“ os”模块没有“ sched_getaffinity”方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆