Message336117
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 |
|
Date |
User |
Action |
Args |
2019-02-20 16:56:22 | keirlawson | set | recipients:
+ keirlawson |
2019-02-20 16:56:22 | keirlawson | set | messageid: <1550681782.39.0.211832814896.issue36054@roundup.psfhosted.org> |
2019-02-20 16:56:22 | keirlawson | link | issue36054 messages |
2019-02-20 16:56:22 | keirlawson | create | |
|