Author: Joannah Nanjekye <nanjekyejoan...@gmail.com> Branch: get/setpriority Changeset: r90381:fcaf312e010c Date: 2017-01-09 14:06 +0300 http://bitbucket.org/pypy/pypy/changeset/fcaf312e010c/
Log: exposed prio_process,prio_user,prio_pgrp diff --git a/lib-python/2.7/os.py b/lib-python/2.7/os.py --- a/lib-python/2.7/os.py +++ b/lib-python/2.7/os.py @@ -124,12 +124,11 @@ # Python uses fixed values for the SEEK_ constants; they are mapped # to native constants if necessary in posixmodule.c +# Other possible SEEK values are directly imported from posixmodule.c SEEK_SET = 0 SEEK_CUR = 1 SEEK_END = 2 -#' - # Super directory utilities. # (Inspired by Eric Raymond; the doc strings are mostly his) 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 @@ -83,6 +83,9 @@ 'set_inheritable': 'interp_posix.set_inheritable', 'getpriority': 'interp_posix.getpriority', 'setpriority': 'interp_posix.setpriority', + 'PRIO_PROCESS': 'space.newint(0)', + 'PRIO_PGRP': 'space.newint(1)', + 'PRIO_USER': 'space.newint(2)', } if hasattr(os, 'chown'): 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 @@ -1847,7 +1847,7 @@ Get program scheduling priority. """ try: - returned_priority = rposix.getpriority(program, identifier) + returned_priority = rposix.c_getpriority(program, identifier) except OSError as e: raise wrap_oserror(space, e) return space.wrap(returned_priority) @@ -1859,7 +1859,7 @@ Set program scheduling priority. """ try: - rposix.setpriority(program, identifier, priority) + rposix.c_setpriority(program, identifier, priority) except OSError as e: raise wrap_oserror(space, e) diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py --- a/pypy/module/posix/test/test_posix2.py +++ b/pypy/module/posix/test/test_posix2.py @@ -850,16 +850,21 @@ assert st.st_size == 10000000000 test_largefile.need_sparse_files = True - def test_os_getpriority(self): + def test_os_set_get_priority(self): posix, os = self.posix, self.os - assert os.getpriority(0,os.getpid()) == posix.getpriority(0,os.getpid()) - - def test_os_setpriority(self): - posix, os = self.posix, self.os - orig_priority = posix.getpriority(0, os.getpid()) - posix.setpriority(0, os.getpid(), orig_priority + 1) - new_result = posix.getpriority(0, os.getpid()) - assert new_result == (orig_priority + 1) + orig_priority = posix.getpriority(posix.PRIO_PROCESS, os.getpid()) + posix.setpriority(posix.PRIO_PROCESS, os.getpid(), orig_priority + 1) + assert orig_priority == 0 + assert posix.getpriority(posix.PRIO_PGRP, os.getpid()) == 0 + try: + new_result = posix.getpriority(posix.PRIO_PROCESS, os.getpid()) + assert new_result == (orig_priority + 1) + finally: + try: + posix.setpriority(posix.PRIO_PROCESS, posix.getpid(), orig_priority) + except OSError as err: + if err.errno != errno.EACCES: + raise def test_write_buffer(self): os = self.posix diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -249,6 +249,9 @@ SEEK_SET = rffi_platform.DefinedConstantInteger('SEEK_SET') SEEK_CUR = rffi_platform.DefinedConstantInteger('SEEK_CUR') SEEK_END = rffi_platform.DefinedConstantInteger('SEEK_END') + PRIO_PROCESS = rffi_platform.DefinedConstantInteger('PRIO_PROCESS') + PRIO_PGRP = rffi_platform.DefinedConstantInteger('PRIO_PGRP') + PRIO_USER = rffi_platform.DefinedConstantInteger('PRIO_USER') O_NONBLOCK = rffi_platform.DefinedConstantInteger('O_NONBLOCK') OFF_T_SIZE = rffi_platform.SizeOf('off_t') @@ -1738,15 +1741,7 @@ save_err=rffi.RFFI_SAVE_ERRNO) c_setpriority = external('setpriority', [rffi.INT, rffi.INT, rffi.INT], rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO) - - @replace_os_function('getpriority') - def getpriority(program, identifier): - return handle_posix_error('getpriority', c_getpriority(program, identifier)) - - @replace_os_function('setpriority') - def setpriority(program, identifier, priority): - handle_posix_error('setpriority', c_setpriority(program, identifier, priority)) - + #___________________________________________________________________ c_chroot = external('chroot', [rffi.CCHARP], rffi.INT, diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py --- a/rpython/rlib/test/test_rposix.py +++ b/rpython/rlib/test/test_rposix.py @@ -663,3 +663,4 @@ finally: os.close(fd1) os.close(fd2) + \ No newline at end of file _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit