Skip to content

Commit

Permalink
Merge branch 'master' into get_open_files_thread
Browse files Browse the repository at this point in the history
* master:
  use 'with open' to make sure file is closed
  test_process_create_time: always test against the rounded time too
  don't test physical cpu count on systems that don't include it
  don't test num_ctx_switches on unsupported kernels
  fix compilation warning about possible misuse of XDECREF
  fix race condition in wait_for_file
  fix flake8 error
  fix permission errors when running from /root
  fix giampaolo#607: DUPLEX_UNKNOWN is not defined on old RedHat versions
  fix giampaolo#606: Process.parent() may swallow NoSuchProcess exceptions (#race-condition)
  attempt to fix xargs on OSX
  giampaolo#602: move pre-commit hook into a separate file
  fix giampaolo#602: add GIT pre-commit hook
  fix failing test on Windows
  C styling: if unification
  forgot to close the handle
  fix giampaolo#599 (Windows): process name() can now be determined for all PIDs
  add test
  windows: refactoring of the alternative process info implementation
  fix typo in documentation
  • Loading branch information
mrjefftang committed Mar 24, 2015
2 parents c813e6d + 241c6ba commit 93e48b1
Show file tree
Hide file tree
Showing 23 changed files with 549 additions and 774 deletions.
25 changes: 25 additions & 0 deletions .git-pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# This script gets executed on "git commit -am '...'".
# You can install it with "make install-git-hooks".

# pdb
pdb=`git diff --cached --name-only | \
grep -E '\.py$' | \
xargs grep -n -H -E '(pdb\.set_trace\(\))'`
if [ ! -z "$pdb" ] ; then
echo "commit aborted: you forgot a pdb in your python code"
echo $pdb
exit 1
fi

# flake8
flake8=`git diff --cached --name-only | grep -E '\.py$'`
if [ ! -z "$flake8" ] ; then
flake8=`echo "$flake8" | xargs flake8`
if [ ! -z "$flake8" ] ; then
echo "commit aborted: python code is not flake8-compliant"
echo $flake8
exit 1
fi
fi
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues

**Enhancements**

- #250: new psutil.net_if_stats() returning NIC statistics (isup, duplex,
speed, MTU).
- #376: new psutil.net_if_addrs() returning all NIC addresses a-la ifconfig.
- #469: on Python >= 3.4 ``IOPRIO_CLASS_*`` and ``*_PRIORITY_CLASS`` constants
returned by psutil.Process' ionice() and nice() methods are enums instead of
Expand All @@ -16,6 +18,9 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #589: Process.cpu_affinity() accepts any kind of iterable (set, tuple, ...),
not only lists.
- #594: all deprecated APIs were removed.
- #599: [Windows] process name() can now be determined for all processes even
when running as a limited user.
- #602: pre-commit GIT hook.

**Bug fixes**

Expand All @@ -30,6 +35,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #586: [FreeBSD] cpu_affinity() segfaults on set in case an invalid CPU
number is provided.
- #593: [FreeBSD] Process().memory_maps() segfaults.
- #606: Process.parent() may swallow NoSuchProcess exceptions.


2.2.1 - 2015-02-02
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include .git-pre-commit
include .gitignore
include .travis.yml
include CREDITS
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ upload-doc:
git-tag-release:
git tag -a release-`python -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD`
echo "done; now run 'git push --follow-tags' to push the new tag on the remote repo"

# install GIT pre-commit hook
install-git-hooks:
cp .git-pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
21 changes: 16 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ HIGHER PRIORITY
* #371: CPU temperature (apparently OSX and Linux only; on Linux it requires
lm-sensors lib).

* #269: expose network ifaces RX/TW queues.
* #269: expose network ifaces RX/TW queues. This should probably go into
net_if_stats(). Figure out on what platforms this is supported:
Linux: yes
Others: ?

* Process.threads(): thread names; patch for OSX available at:
https://code.google.com/p/plcrashreporter/issues/detail?id=65
Expand Down Expand Up @@ -85,10 +88,18 @@ DEBATABLE
Also, we can probably reimplement wait_pid() on POSIX which is currently
implemented as a busy-loop.

* Certain systems (XXX figure out which ones exactly) provide CPU times about
process children. On those systems Process.cpu_times() might return
a (user, system, user_children, system_children) ntuple.
Also, os.times() provides 'elapsed' times as well.
* Certain systems provide CPU times about process children. On those systems
Process.cpu_times() might return a (user, system, user_children,
system_children) ntuple.
* Linux: /proc/{PID}/stat
* Solaris: pr_cutime and pr_cstime
* FreeBSD: none
* OSX: none
* Windows: none

* ...also, os.times() provides 'elapsed' times as well.

* ...also Linux provides guest_time and cguest_time.

* Enrich exception classes hierarchy on Python >= 3.3 / post PEP-3151 so that:
- NoSuchProcess inherits from ProcessLookupError
Expand Down
14 changes: 7 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CPU
- **guest** *(Linux 2.6.24+)*
- **guest_nice** *(Linux 3.2.0+)*

When *percpu* is ``True`` return a list of nameduples for each logical CPU
When *percpu* is ``True`` return a list of namedtuples for each logical CPU
on the system.
First element of the list refers to first CPU, second element to second CPU
and so on.
Expand Down Expand Up @@ -275,7 +275,7 @@ Disks

If *perdisk* is ``True`` return the same information for every physical disk
installed on the system as a dictionary with partition names as the keys and
the namedutuple described above as the values.
the namedtuple described above as the values.
See `examples/iotop.py <https://github.com/giampaolo/psutil/blob/master/examples/iotop.py>`__
for an example application.

Expand Down Expand Up @@ -322,7 +322,7 @@ Network

.. function:: net_connections(kind='inet')

Return system-wide socket connections as a list of namedutples.
Return system-wide socket connections as a list of namedtuples.
Every namedtuple provides 7 attributes:

- **fd**: the socket file descriptor, if retrievable, else ``-1``.
Expand Down Expand Up @@ -733,7 +733,7 @@ Process class
.. method:: uids()

The **real**, **effective** and **saved** user ids of this process as a
nameduple. This is the same as
namedtuple. This is the same as
`os.getresuid() <http://docs.python.org//library/os.html#os.getresuid>`__
but can be used for every process PID.

Expand All @@ -742,7 +742,7 @@ Process class
.. method:: gids()

The **real**, **effective** and **saved** group ids of this process as a
nameduple. This is the same as
namedtuple. This is the same as
`os.getresgid() <http://docs.python.org//library/os.html#os.getresgid>`__
but can be used for every process PID.

Expand Down Expand Up @@ -1003,7 +1003,7 @@ Process class

.. method:: memory_maps(grouped=True)

Return process's mapped memory regions as a list of nameduples whose
Return process's mapped memory regions as a list of namedtuples whose
fields are variable depending on the platform. As such, portable
applications should rely on namedtuple's `path` and `rss` fields only.
This method is useful to obtain a detailed representation of process
Expand Down Expand Up @@ -1066,7 +1066,7 @@ Process class

.. method:: connections(kind="inet")

Return socket connections opened by process as a list of namedutples.
Return socket connections opened by process as a list of namedtuples.
To get system-wide connections use :func:`psutil.net_connections()`.
Every namedtuple provides 6 attributes:

Expand Down
18 changes: 8 additions & 10 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,10 @@ def parent(self):
"""
ppid = self.ppid()
if ppid is not None:
ctime = self.create_time()
try:
parent = Process(ppid)
if parent.create_time() <= self.create_time():
if parent.create_time() <= ctime:
return parent
# ...else ppid has been reused by another process
except NoSuchProcess:
Expand Down Expand Up @@ -513,13 +514,10 @@ def ppid(self):
# XXX should we check creation time here rather than in
# Process.parent()?
if _POSIX:
ppid = self._proc.ppid()
return self._proc.ppid()
else:
if self._ppid is None:
ppid = self._proc.ppid()
self._ppid = ppid
self._proc._ppid = ppid
return ppid
self._ppid = self._ppid or self._proc.ppid()
return self._ppid

def name(self):
"""The process name. The return value is cached after first call."""
Expand Down Expand Up @@ -958,7 +956,7 @@ def memory_percent(self):
return 0.0

def memory_maps(self, grouped=True):
"""Return process' mapped memory regions as a list of nameduples
"""Return process' mapped memory regions as a list of namedtuples
whose fields are variable depending on the platform.
If 'grouped' is True the mapped regions with the same 'path'
Expand Down Expand Up @@ -1376,7 +1374,7 @@ def cpu_times(percpu=False):
- guest (Linux >= 2.6.24)
- guest_nice (Linux >= 3.2.0)
When percpu is True return a list of nameduples for each CPU.
When percpu is True return a list of namedtuples for each CPU.
First element of the list refers to first CPU, second element
to second CPU and so on.
The order of the list is consistent across calls.
Expand Down Expand Up @@ -1663,7 +1661,7 @@ def disk_io_counters(perdisk=False):
If perdisk is True return the same information for every
physical disk installed on the system as a dictionary
with partition names as the keys and the namedutuple
with partition names as the keys and the namedtuple
described above as the values.
On recent Windows versions 'diskperf -y' command may need to be
Expand Down
4 changes: 2 additions & 2 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def disk_io_counters():


def disk_partitions(all=False):
"""Return mounted disk partitions as a list of nameduples"""
"""Return mounted disk partitions as a list of namedtuples"""
phydevs = []
with open("/proc/filesystems", "r") as f:
for line in f:
Expand Down Expand Up @@ -855,7 +855,7 @@ def memory_info_ex(self):

@wrap_exceptions
def memory_maps(self):
"""Return process's mapped memory regions as a list of nameduples.
"""Return process's mapped memory regions as a list of named tuples.
Fields are explained in 'man proc'; here is an updated (Apr 2012)
version: http://goo.gl/fmebo
"""
Expand Down
Loading

0 comments on commit 93e48b1

Please sign in to comment.