Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 996
Aki Avatar asked Mar 01 '17 17:03

Aki


People also ask

How do I open an os module file in Python?

open() method in Python is used to open a specified file path and set various flags according to the specified flags and its mode according to specified mode. This method returns a file descriptor for newly open file. The returned file descriptor is non-inheritable.

What is the os module in Python?

The OS module in Python provides functions for creating and removing a directory (folder), fetching its contents, changing and identifying the current directory, etc. You first need to import the os module to interact with the underlying operating system.

What is import os in Python?

system. Python os system function allows us to run a command in the Python script, just like if I was running it in my shell. For example: import os currentFiles = os.system("users > users.txt")

What is os name in Python?

The os.name method in Python get the name of the underlying operating system (OS). This is a method of the OS module. The following are the operating systems that are currently registered. RISC OS. Portable Operating System Interface (POSIX)


1 Answers

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

like image 184
Irmen de Jong Avatar answered Sep 20 '22 07:09

Irmen de Jong