[pypy-commit] pypy py3.5: expose cpu_count to os module

plan_rich pypy.commits at gmail.com
Fri Oct 14 10:03:49 EDT 2016


Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5
Changeset: r87790:fcb708c77a65
Date: 2016-10-14 15:24 +0200
http://bitbucket.org/pypy/pypy/changeset/fcb708c77a65/

Log:	expose cpu_count to os module

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -42,6 +42,7 @@
         'read': 'interp_posix.read',
         'close': 'interp_posix.close',
         'closerange': 'interp_posix.closerange',
+        'cpu_count': 'interp_posix.cpu_count',
 
         'fstat': 'interp_posix.fstat',
         'stat': 'interp_posix.stat',
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -2211,3 +2211,9 @@
                                     space.wrap('terminal_size'))
 
     return space.call_function(w_terminal_size, w_tuple)
+
+def cpu_count(space):
+    count = rposix.cpu_count()
+    if count <= 0:
+        return space.w_None
+    return space.wrap(count)
diff --git a/pypy/module/posix/test/test_interp_posix.py b/pypy/module/posix/test/test_interp_posix.py
--- a/pypy/module/posix/test/test_interp_posix.py
+++ b/pypy/module/posix/test/test_interp_posix.py
@@ -22,6 +22,7 @@
         child.logfile = sys.stdout
         return child
 
+
     def spawn(self, argv):
         py_py = py.path.local(pypydir).join('bin', 'pyinteractive.py')
         return self._spawn(sys.executable, [str(py_py), '-S'] + argv)
@@ -59,3 +60,12 @@
         err = (sec * 10**9 + nsec) - (s * 10**9 + ns)
         assert -MAX_ERR < err < MAX_ERR
     _test_convert_seconds_full(space)
+
+class AppTestOS:
+    spaceconfig = {'usemodules': []}
+    def test_cpu_count(self):
+        """
+        import os
+        cc = os.cpu_count()
+        assert cc is None or (isinstance(cc, int) and cc > 0)
+        """


More information about the pypy-commit mailing list