New submission from Keir Lawson <keirlaw...@gmail.com>:
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 <rep...@bugs.python.org> <https://bugs.python.org/issue36054> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com