Backed out changeset 697eb6db7d96 (bug 930808) for OS X make check failures

This commit is contained in:
Phil Ringnalda
2014-12-23 21:04:19 -08:00
parent 1f9098f7ac
commit db84ee33c0
88 changed files with 7316 additions and 13627 deletions

View File

@@ -6,49 +6,29 @@
"""Routines common to all posix systems."""
import errno
import glob
import os
import errno
import psutil
import sys
import time
import glob
from psutil._common import sdiskusage, usage_percent, memoize
from psutil._compat import PY3, unicode
class TimeoutExpired(Exception):
pass
from psutil._error import TimeoutExpired
from psutil._common import nt_diskinfo, usage_percent, memoize
def pid_exists(pid):
"""Check whether pid exists in the current process table."""
if pid == 0:
# According to "man 2 kill" PID 0 has a special meaning:
# it refers to <<every process in the process group of the
# calling process>> so we don't want to go any further.
# If we get here it means this UNIX platform *does* have
# a process with id 0.
return True
if pid < 0:
return False
try:
os.kill(pid, 0)
except OSError:
err = sys.exc_info()[1]
if err.errno == errno.ESRCH:
# ESRCH == No such process
return False
elif err.errno == errno.EPERM:
# EPERM clearly means there's a process to deny access to
return True
else:
# According to "man 2 kill" possible error values are
# (EINVAL, EPERM, ESRCH) therefore we should never get
# here. If we do let's be explicit in considering this
# an error.
raise err
e = sys.exc_info()[1]
return e.errno == errno.EPERM
else:
return True
def wait_pid(pid, timeout=None):
"""Wait for process with pid 'pid' to terminate and return its
exit status code as an integer.
@@ -63,7 +43,7 @@ def wait_pid(pid, timeout=None):
def check_timeout(delay):
if timeout is not None:
if timer() >= stop_at:
raise TimeoutExpired()
raise TimeoutExpired(pid)
time.sleep(delay)
return min(delay * 2, 0.04)
@@ -114,24 +94,9 @@ def wait_pid(pid, timeout=None):
# should never happen
raise RuntimeError("unknown process exit status")
def disk_usage(path):
def get_disk_usage(path):
"""Return disk usage associated with path."""
try:
st = os.statvfs(path)
except UnicodeEncodeError:
if not PY3 and isinstance(path, unicode):
# this is a bug with os.statvfs() and unicode on
# Python 2, see:
# - https://github.com/giampaolo/psutil/issues/416
# - http://bugs.python.org/issue18695
try:
path = path.encode(sys.getfilesystemencoding())
except UnicodeEncodeError:
pass
st = os.statvfs(path)
else:
raise
st = os.statvfs(path)
free = (st.f_bavail * st.f_frsize)
total = (st.f_blocks * st.f_frsize)
used = (st.f_blocks - st.f_bfree) * st.f_frsize
@@ -139,8 +104,7 @@ def disk_usage(path):
# NB: the percentage is -5% than what shown by df due to
# reserved blocks that we are currently not considering:
# http://goo.gl/sWGbH
return sdiskusage(total, used, free, percent)
return nt_diskinfo(total, used, free, percent)
@memoize
def _get_terminal_map():