[pypy-svn] r79990 - in pypy/branch/more-posix/pypy/module/posix: . test

arigo at codespeak.net arigo at codespeak.net
Sat Dec 11 17:47:31 CET 2010


Author: arigo
Date: Sat Dec 11 17:47:29 2010
New Revision: 79990

Modified:
   pypy/branch/more-posix/pypy/module/posix/__init__.py
   pypy/branch/more-posix/pypy/module/posix/interp_posix.py
   pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py
Log:
os.nice().

Modified: pypy/branch/more-posix/pypy/module/posix/__init__.py
==============================================================================
--- pypy/branch/more-posix/pypy/module/posix/__init__.py	(original)
+++ pypy/branch/more-posix/pypy/module/posix/__init__.py	Sat Dec 11 17:47:29 2010
@@ -119,6 +119,8 @@
         interpleveldefs['mkfifo'] = 'interp_posix.mkfifo'
     if hasattr(os, 'mknod'):
         interpleveldefs['mknod'] = 'interp_posix.mknod'
+    if hasattr(os, 'nice'):
+        interpleveldefs['nice'] = 'interp_posix.nice'
 
     for name in ['setsid', 'getuid', 'geteuid', 'getgid', 'getegid', 'setuid',
                  'seteuid', 'setgid', 'setegid', 'getpgrp', 'setpgrp',

Modified: pypy/branch/more-posix/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/more-posix/pypy/module/posix/interp_posix.py	(original)
+++ pypy/branch/more-posix/pypy/module/posix/interp_posix.py	Sat Dec 11 17:47:29 2010
@@ -1011,6 +1011,15 @@
                            space.wrap(load[2])])
 getloadavg.unwrap_spec = [ObjSpace]
 
+def nice(space, inc):
+    "Decrease the priority of process by inc and return the new priority."
+    try:
+        res = os.nice(inc)
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    return space.wrap(res)
+nice.unwrap_spec = [ObjSpace, "c_int"]
+
 if _WIN:
     from pypy.rlib import rwin32
 

Modified: pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py	Sat Dec 11 17:47:29 2010
@@ -696,6 +696,21 @@
                     assert stat.S_ISCHR(st.st_mode)
                     assert st.st_rdev == 0x105
 
+    if hasattr(os, 'nice') and hasattr(os, 'fork') and hasattr(os, 'waitpid'):
+        def test_nice(self):
+            os = self.posix
+            myprio = os.nice(0)
+            #
+            pid = os.fork()
+            if pid == 0:    # in the child
+                res = os.nice(3)
+                os._exit(res)
+            #
+            pid1, status1 = os.waitpid(pid, 0)
+            assert pid1 == pid
+            assert os.WIFEXITED(status1)
+            assert os.WEXITSTATUS(status1) == myprio + 3
+
 
 class AppTestEnvironment(object):
     def setup_class(cls): 



More information about the Pypy-commit mailing list