Skip to content

Commit

Permalink
Re. #1210: add doc warning explaining that cpu_times() values can som…
Browse files Browse the repository at this point in the history
…etimes go backwards

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
  • Loading branch information
giampaolo committed May 3, 2021
1 parent b035d1f commit 4d30272
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
21 changes: 2 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ Process management
>>> p
psutil.Process(pid=7055, name='python3', status='running', started='09:04:44')
>>> p.name()
'python'
'python3'
>>> p.exe()
'/usr/bin/python'
'/usr/bin/python3'
>>> p.cwd()
'/home/giampaolo'
>>> p.cmdline()
Expand Down Expand Up @@ -444,23 +444,6 @@ Further process APIs
>>> gone, alive = psutil.wait_procs(procs_list, timeout=3, callback=on_terminate)
>>>
Popen wrapper:
.. code-block:: python
>>> import psutil
>>> from subprocess import PIPE
>>> p = psutil.Popen(["/usr/bin/python", "-c", "print('hello')"], stdout=PIPE)
>>> p.name()
'python'
>>> p.username()
'giampaolo'
>>> p.communicate()
('hello\n', None)
>>> p.wait(timeout=2)
0
>>>
Windows services
----------------
Expand Down
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ CPU

.. versionchanged:: 4.1.0 added *interrupt* and *dpc* fields on Windows.

.. warning::
CPU times are always supposed to increase over time, or at least remain
the same, and that's because time cannot go backwards.
Surprisingly sometimes this might not be the case (at least on Windows
and Linux), see `#1210 <https://github.com/giampaolo/psutil/issues/1210#issuecomment-363046156>`__.

.. function:: cpu_percent(interval=None, percpu=False)

Return a float representing the current system-wide CPU utilization as a
Expand Down
1 change: 0 additions & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,6 @@ def cpu_percent(interval=None, percpu=False):

def calculate(t1, t2):
times_delta = _cpu_times_deltas(t1, t2)

all_delta = _cpu_tot_time(times_delta)
busy_delta = _cpu_busy_time(times_delta)

Expand Down

0 comments on commit 4d30272

Please sign in to comment.