[issue36054] On Linux, os.count() should read cgroup cpu.shares and cpu.cfs (CPU count inside docker container)

2020-03-23 Thread Keir Lawson


Change by Keir Lawson :


--
nosy:  -keirlawson

___
Python tracker 
<https://bugs.python.org/issue36054>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36054] Way to detect CPU count inside docker container

2019-02-20 Thread Keir Lawson


New submission from Keir Lawson :

There appears to be no way to detect the number of CPUs allotted to a Python 
program within a docker container.  With the following script:

import os

print("os.cpu_count(): " + str(os.cpu_count()))
print("len(os.sched_getaffinity(0)): " + str(len(os.sched_getaffinity(0

when run in a container (from an Ubuntu 18.04 host) I get:

docker run -v "$PWD":/src/ -w /src/ --cpus=1 python:3.7 python detect_cpus.py
os.cpu_count(): 4
len(os.sched_getaffinity(0)): 4

Recent vesions of Java are able to correctly detect the CPU allocation:

docker run -it --cpus 1 openjdk:10-jdk
Feb 20, 2019 4:20:29 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
|  Welcome to JShell -- Version 10.0.2
|  For an introduction type: /help intro

jshell> Runtime.getRuntime().availableProcessors()
$1 ==> 1

--
components: Library (Lib)
messages: 336117
nosy: keirlawson
priority: normal
severity: normal
status: open
title: Way to detect CPU count inside docker container
type: performance
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue36054>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36054] Way to detect CPU count inside docker container

2019-02-20 Thread Keir Lawson


Keir Lawson  added the comment:

I believe this is related to this ticket: https://bugs.python.org/issue26692

Looking at Java's implementation it seems like they are checking if cgroups are 
enabled via /proc/self/cgroup and then if it is parsing the cgroup information 
out of the filesystem.

--

___
Python tracker 
<https://bugs.python.org/issue36054>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com