summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-02-01 15:39:25 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-02-01 15:39:25 +0100
commit2b59a12cc00e0b0f593547b9b56350400f9fdfc8 (patch)
tree536ed2a19a697385ed9c6e0227698f4879821659
parent86fc3ee3acb2d2ae0e8186b1ae8a55567417759a (diff)
parentb524439056484e81a17407dc31cfcea1ff81715b (diff)
downloadpsutil-371-temperatures.tar.gz
merge from master371-temperatures
-rw-r--r--CREDITS4
-rw-r--r--HISTORY.rst206
-rw-r--r--README.rst19
-rw-r--r--appveyor.yml3
-rw-r--r--docs/index.rst35
-rw-r--r--psutil/__init__.py8
-rw-r--r--psutil/_pslinux.py21
-rw-r--r--psutil/_psposix.py2
-rw-r--r--psutil/arch/windows/services.c6
-rwxr-xr-xpsutil/tests/test_linux.py5
-rwxr-xr-xpsutil/tests/test_osx.py2
-rwxr-xr-xpsutil/tests/test_process.py27
-rwxr-xr-xpsutil/tests/test_system.py7
-rwxr-xr-xscripts/internal/winmake.py1
14 files changed, 301 insertions, 45 deletions
diff --git a/CREDITS b/CREDITS
index 031548ae..a353b3da 100644
--- a/CREDITS
+++ b/CREDITS
@@ -425,3 +425,7 @@ N: Pierre Fersing
C: France
E: pierre.fersing@bleemeo.com
I: 950
+
+N: Thiago Borges Abdnur
+W: https://github.com/bolaum
+I: 959
diff --git a/HISTORY.rst b/HISTORY.rst
index 52cb04d0..fb7cddef 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -9,6 +9,8 @@
- 357_: added psutil.Process.cpu_num() (what CPU a process is on).
- 941_: added psutil.cpu_freq() (CPU frequency).
+- 956_: cpu_affinity([]) can now be used as an alias to set affinity against
+ all eligible CPUs.
**Bug fixes**
@@ -17,6 +19,9 @@
- 948_: cannot install psutil with PYTHONOPTIMIZE=2.
- 950_: [Windows] Process.cpu_percent() was calculated incorrectly and showed
higher number than real usage.
+- 959_: psutil exception objects could not be pickled.
+- 960_: Popen.wait() did not return the correct negative exit status if process
+ is ``kill()``ed by a signal.
- 961_: [Windows] WindowsService.description() may fail with
ERROR_MUI_FILE_NOT_FOUND.
@@ -2462,3 +2467,204 @@ DeprecationWarning.
.. _997: https://github.com/giampaolo/psutil/issues/997
.. _998: https://github.com/giampaolo/psutil/issues/998
.. _999: https://github.com/giampaolo/psutil/issues/999
+.. _1000: https://github.com/giampaolo/psutil/issues/1000
+.. _1001: https://github.com/giampaolo/psutil/issues/1001
+.. _1002: https://github.com/giampaolo/psutil/issues/1002
+.. _1003: https://github.com/giampaolo/psutil/issues/1003
+.. _1004: https://github.com/giampaolo/psutil/issues/1004
+.. _1005: https://github.com/giampaolo/psutil/issues/1005
+.. _1006: https://github.com/giampaolo/psutil/issues/1006
+.. _1007: https://github.com/giampaolo/psutil/issues/1007
+.. _1008: https://github.com/giampaolo/psutil/issues/1008
+.. _1009: https://github.com/giampaolo/psutil/issues/1009
+.. _1010: https://github.com/giampaolo/psutil/issues/1010
+.. _1011: https://github.com/giampaolo/psutil/issues/1011
+.. _1012: https://github.com/giampaolo/psutil/issues/1012
+.. _1013: https://github.com/giampaolo/psutil/issues/1013
+.. _1014: https://github.com/giampaolo/psutil/issues/1014
+.. _1015: https://github.com/giampaolo/psutil/issues/1015
+.. _1016: https://github.com/giampaolo/psutil/issues/1016
+.. _1017: https://github.com/giampaolo/psutil/issues/1017
+.. _1018: https://github.com/giampaolo/psutil/issues/1018
+.. _1019: https://github.com/giampaolo/psutil/issues/1019
+.. _1020: https://github.com/giampaolo/psutil/issues/1020
+.. _1021: https://github.com/giampaolo/psutil/issues/1021
+.. _1022: https://github.com/giampaolo/psutil/issues/1022
+.. _1023: https://github.com/giampaolo/psutil/issues/1023
+.. _1024: https://github.com/giampaolo/psutil/issues/1024
+.. _1025: https://github.com/giampaolo/psutil/issues/1025
+.. _1026: https://github.com/giampaolo/psutil/issues/1026
+.. _1027: https://github.com/giampaolo/psutil/issues/1027
+.. _1028: https://github.com/giampaolo/psutil/issues/1028
+.. _1029: https://github.com/giampaolo/psutil/issues/1029
+.. _1030: https://github.com/giampaolo/psutil/issues/1030
+.. _1031: https://github.com/giampaolo/psutil/issues/1031
+.. _1032: https://github.com/giampaolo/psutil/issues/1032
+.. _1033: https://github.com/giampaolo/psutil/issues/1033
+.. _1034: https://github.com/giampaolo/psutil/issues/1034
+.. _1035: https://github.com/giampaolo/psutil/issues/1035
+.. _1036: https://github.com/giampaolo/psutil/issues/1036
+.. _1037: https://github.com/giampaolo/psutil/issues/1037
+.. _1038: https://github.com/giampaolo/psutil/issues/1038
+.. _1039: https://github.com/giampaolo/psutil/issues/1039
+.. _1040: https://github.com/giampaolo/psutil/issues/1040
+.. _1041: https://github.com/giampaolo/psutil/issues/1041
+.. _1042: https://github.com/giampaolo/psutil/issues/1042
+.. _1043: https://github.com/giampaolo/psutil/issues/1043
+.. _1044: https://github.com/giampaolo/psutil/issues/1044
+.. _1045: https://github.com/giampaolo/psutil/issues/1045
+.. _1046: https://github.com/giampaolo/psutil/issues/1046
+.. _1047: https://github.com/giampaolo/psutil/issues/1047
+.. _1048: https://github.com/giampaolo/psutil/issues/1048
+.. _1049: https://github.com/giampaolo/psutil/issues/1049
+.. _1050: https://github.com/giampaolo/psutil/issues/1050
+.. _1051: https://github.com/giampaolo/psutil/issues/1051
+.. _1052: https://github.com/giampaolo/psutil/issues/1052
+.. _1053: https://github.com/giampaolo/psutil/issues/1053
+.. _1054: https://github.com/giampaolo/psutil/issues/1054
+.. _1055: https://github.com/giampaolo/psutil/issues/1055
+.. _1056: https://github.com/giampaolo/psutil/issues/1056
+.. _1057: https://github.com/giampaolo/psutil/issues/1057
+.. _1058: https://github.com/giampaolo/psutil/issues/1058
+.. _1059: https://github.com/giampaolo/psutil/issues/1059
+.. _1060: https://github.com/giampaolo/psutil/issues/1060
+.. _1061: https://github.com/giampaolo/psutil/issues/1061
+.. _1062: https://github.com/giampaolo/psutil/issues/1062
+.. _1063: https://github.com/giampaolo/psutil/issues/1063
+.. _1064: https://github.com/giampaolo/psutil/issues/1064
+.. _1065: https://github.com/giampaolo/psutil/issues/1065
+.. _1066: https://github.com/giampaolo/psutil/issues/1066
+.. _1067: https://github.com/giampaolo/psutil/issues/1067
+.. _1068: https://github.com/giampaolo/psutil/issues/1068
+.. _1069: https://github.com/giampaolo/psutil/issues/1069
+.. _1070: https://github.com/giampaolo/psutil/issues/1070
+.. _1071: https://github.com/giampaolo/psutil/issues/1071
+.. _1072: https://github.com/giampaolo/psutil/issues/1072
+.. _1073: https://github.com/giampaolo/psutil/issues/1073
+.. _1074: https://github.com/giampaolo/psutil/issues/1074
+.. _1075: https://github.com/giampaolo/psutil/issues/1075
+.. _1076: https://github.com/giampaolo/psutil/issues/1076
+.. _1077: https://github.com/giampaolo/psutil/issues/1077
+.. _1078: https://github.com/giampaolo/psutil/issues/1078
+.. _1079: https://github.com/giampaolo/psutil/issues/1079
+.. _1080: https://github.com/giampaolo/psutil/issues/1080
+.. _1081: https://github.com/giampaolo/psutil/issues/1081
+.. _1082: https://github.com/giampaolo/psutil/issues/1082
+.. _1083: https://github.com/giampaolo/psutil/issues/1083
+.. _1084: https://github.com/giampaolo/psutil/issues/1084
+.. _1085: https://github.com/giampaolo/psutil/issues/1085
+.. _1086: https://github.com/giampaolo/psutil/issues/1086
+.. _1087: https://github.com/giampaolo/psutil/issues/1087
+.. _1088: https://github.com/giampaolo/psutil/issues/1088
+.. _1089: https://github.com/giampaolo/psutil/issues/1089
+.. _1090: https://github.com/giampaolo/psutil/issues/1090
+.. _1091: https://github.com/giampaolo/psutil/issues/1091
+.. _1092: https://github.com/giampaolo/psutil/issues/1092
+.. _1093: https://github.com/giampaolo/psutil/issues/1093
+.. _1094: https://github.com/giampaolo/psutil/issues/1094
+.. _1095: https://github.com/giampaolo/psutil/issues/1095
+.. _1096: https://github.com/giampaolo/psutil/issues/1096
+.. _1097: https://github.com/giampaolo/psutil/issues/1097
+.. _1098: https://github.com/giampaolo/psutil/issues/1098
+.. _1099: https://github.com/giampaolo/psutil/issues/1099
+.. _1100: https://github.com/giampaolo/psutil/issues/1100
+.. _1101: https://github.com/giampaolo/psutil/issues/1101
+.. _1102: https://github.com/giampaolo/psutil/issues/1102
+.. _1103: https://github.com/giampaolo/psutil/issues/1103
+.. _1104: https://github.com/giampaolo/psutil/issues/1104
+.. _1105: https://github.com/giampaolo/psutil/issues/1105
+.. _1106: https://github.com/giampaolo/psutil/issues/1106
+.. _1107: https://github.com/giampaolo/psutil/issues/1107
+.. _1108: https://github.com/giampaolo/psutil/issues/1108
+.. _1109: https://github.com/giampaolo/psutil/issues/1109
+.. _1110: https://github.com/giampaolo/psutil/issues/1110
+.. _1111: https://github.com/giampaolo/psutil/issues/1111
+.. _1112: https://github.com/giampaolo/psutil/issues/1112
+.. _1113: https://github.com/giampaolo/psutil/issues/1113
+.. _1114: https://github.com/giampaolo/psutil/issues/1114
+.. _1115: https://github.com/giampaolo/psutil/issues/1115
+.. _1116: https://github.com/giampaolo/psutil/issues/1116
+.. _1117: https://github.com/giampaolo/psutil/issues/1117
+.. _1118: https://github.com/giampaolo/psutil/issues/1118
+.. _1119: https://github.com/giampaolo/psutil/issues/1119
+.. _1120: https://github.com/giampaolo/psutil/issues/1120
+.. _1121: https://github.com/giampaolo/psutil/issues/1121
+.. _1122: https://github.com/giampaolo/psutil/issues/1122
+.. _1123: https://github.com/giampaolo/psutil/issues/1123
+.. _1124: https://github.com/giampaolo/psutil/issues/1124
+.. _1125: https://github.com/giampaolo/psutil/issues/1125
+.. _1126: https://github.com/giampaolo/psutil/issues/1126
+.. _1127: https://github.com/giampaolo/psutil/issues/1127
+.. _1128: https://github.com/giampaolo/psutil/issues/1128
+.. _1129: https://github.com/giampaolo/psutil/issues/1129
+.. _1130: https://github.com/giampaolo/psutil/issues/1130
+.. _1131: https://github.com/giampaolo/psutil/issues/1131
+.. _1132: https://github.com/giampaolo/psutil/issues/1132
+.. _1133: https://github.com/giampaolo/psutil/issues/1133
+.. _1134: https://github.com/giampaolo/psutil/issues/1134
+.. _1135: https://github.com/giampaolo/psutil/issues/1135
+.. _1136: https://github.com/giampaolo/psutil/issues/1136
+.. _1137: https://github.com/giampaolo/psutil/issues/1137
+.. _1138: https://github.com/giampaolo/psutil/issues/1138
+.. _1139: https://github.com/giampaolo/psutil/issues/1139
+.. _1140: https://github.com/giampaolo/psutil/issues/1140
+.. _1141: https://github.com/giampaolo/psutil/issues/1141
+.. _1142: https://github.com/giampaolo/psutil/issues/1142
+.. _1143: https://github.com/giampaolo/psutil/issues/1143
+.. _1144: https://github.com/giampaolo/psutil/issues/1144
+.. _1145: https://github.com/giampaolo/psutil/issues/1145
+.. _1146: https://github.com/giampaolo/psutil/issues/1146
+.. _1147: https://github.com/giampaolo/psutil/issues/1147
+.. _1148: https://github.com/giampaolo/psutil/issues/1148
+.. _1149: https://github.com/giampaolo/psutil/issues/1149
+.. _1150: https://github.com/giampaolo/psutil/issues/1150
+.. _1151: https://github.com/giampaolo/psutil/issues/1151
+.. _1152: https://github.com/giampaolo/psutil/issues/1152
+.. _1153: https://github.com/giampaolo/psutil/issues/1153
+.. _1154: https://github.com/giampaolo/psutil/issues/1154
+.. _1155: https://github.com/giampaolo/psutil/issues/1155
+.. _1156: https://github.com/giampaolo/psutil/issues/1156
+.. _1157: https://github.com/giampaolo/psutil/issues/1157
+.. _1158: https://github.com/giampaolo/psutil/issues/1158
+.. _1159: https://github.com/giampaolo/psutil/issues/1159
+.. _1160: https://github.com/giampaolo/psutil/issues/1160
+.. _1161: https://github.com/giampaolo/psutil/issues/1161
+.. _1162: https://github.com/giampaolo/psutil/issues/1162
+.. _1163: https://github.com/giampaolo/psutil/issues/1163
+.. _1164: https://github.com/giampaolo/psutil/issues/1164
+.. _1165: https://github.com/giampaolo/psutil/issues/1165
+.. _1166: https://github.com/giampaolo/psutil/issues/1166
+.. _1167: https://github.com/giampaolo/psutil/issues/1167
+.. _1168: https://github.com/giampaolo/psutil/issues/1168
+.. _1169: https://github.com/giampaolo/psutil/issues/1169
+.. _1170: https://github.com/giampaolo/psutil/issues/1170
+.. _1171: https://github.com/giampaolo/psutil/issues/1171
+.. _1172: https://github.com/giampaolo/psutil/issues/1172
+.. _1173: https://github.com/giampaolo/psutil/issues/1173
+.. _1174: https://github.com/giampaolo/psutil/issues/1174
+.. _1175: https://github.com/giampaolo/psutil/issues/1175
+.. _1176: https://github.com/giampaolo/psutil/issues/1176
+.. _1177: https://github.com/giampaolo/psutil/issues/1177
+.. _1178: https://github.com/giampaolo/psutil/issues/1178
+.. _1179: https://github.com/giampaolo/psutil/issues/1179
+.. _1180: https://github.com/giampaolo/psutil/issues/1180
+.. _1181: https://github.com/giampaolo/psutil/issues/1181
+.. _1182: https://github.com/giampaolo/psutil/issues/1182
+.. _1183: https://github.com/giampaolo/psutil/issues/1183
+.. _1184: https://github.com/giampaolo/psutil/issues/1184
+.. _1185: https://github.com/giampaolo/psutil/issues/1185
+.. _1186: https://github.com/giampaolo/psutil/issues/1186
+.. _1187: https://github.com/giampaolo/psutil/issues/1187
+.. _1188: https://github.com/giampaolo/psutil/issues/1188
+.. _1189: https://github.com/giampaolo/psutil/issues/1189
+.. _1190: https://github.com/giampaolo/psutil/issues/1190
+.. _1191: https://github.com/giampaolo/psutil/issues/1191
+.. _1192: https://github.com/giampaolo/psutil/issues/1192
+.. _1193: https://github.com/giampaolo/psutil/issues/1193
+.. _1194: https://github.com/giampaolo/psutil/issues/1194
+.. _1195: https://github.com/giampaolo/psutil/issues/1195
+.. _1196: https://github.com/giampaolo/psutil/issues/1196
+.. _1197: https://github.com/giampaolo/psutil/issues/1197
+.. _1198: https://github.com/giampaolo/psutil/issues/1198
+.. _1199: https://github.com/giampaolo/psutil/issues/1199
+.. _1200: https://github.com/giampaolo/psutil/issues/1200
diff --git a/README.rst b/README.rst
index f43b079e..00fbc87e 100644
--- a/README.rst
+++ b/README.rst
@@ -263,9 +263,9 @@ Process management
12.1
>>> p.cpu_affinity()
[0, 1, 2, 3]
- >>> p.cpu_affinity([0]) # set
+ >>> p.cpu_affinity([0, 1]) # set
>>> p.cpu_num()
- 2
+ 1
>>>
>>> p.memory_info()
pmem(rss=10915840, vms=67608576, shared=3313664, text=2310144, lib=0, data=7262208, dirty=0)
@@ -389,21 +389,18 @@ Windows services
'username': 'NT AUTHORITY\\LocalService'}
======
-Donate
+Author
======
+psutil was created and is maintained by
+`Giampaolo Rodola' <http://grodola.blogspot.com/p/about.html>`_.
A lot of time and effort went into making psutil as it is right now.
-If you feel psutil is useful to you or your business and want to support its future development please consider donating me (`Giampaolo Rodola' <http://grodola.blogspot.com/p/about.html>`_) some money.
-I only ask for a small donation, but of course I appreciate any amount.
+If you feel psutil is useful to you or your business and want to support its
+future development please consider donating me
+(`Giampaolo <http://grodola.blogspot.com/p/about.html>`_) some money.
.. image:: http://www.paypal.com/en_US/i/btn/x-click-but04.gif
:target: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A9ZS7PKKRM3S8
:alt: Donate via PayPal
Don't want to donate money? Then maybe you could `write me a recommendation on Linkedin <https://www.linkedin.com/in/grodola>`_.
-
-============
-Mailing list
-============
-
-http://groups.google.com/group/psutil/
diff --git a/appveyor.yml b/appveyor.yml
index 4428f776..b569a7ad 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,3 +1,5 @@
+# Build: 0 (bump this up by 1 to force an appveyor run)
+
os: Visual Studio 2015
environment:
@@ -124,4 +126,3 @@ only_commits:
psutil/tests/test_windows.py
scripts/*
setup.py
-
diff --git a/docs/index.rst b/docs/index.rst
index 8cd8875f..87ebf734 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -399,7 +399,7 @@ Disks
.. warning::
on some systems such as Linux, on a very busy or long-lived system these
numbers may wrap (restart from zero), see
- `issues #802 <https://github.com/giampaolo/psutil/issues/802>`__.
+ `issue #802 <https://github.com/giampaolo/psutil/issues/802>`__.
Applications should be prepared to deal with that.
.. versionchanged::
@@ -1249,32 +1249,35 @@ Process class
Get or set process current
`CPU affinity <http://www.linuxjournal.com/article/6799?page=0,0>`__.
- CPU affinity consists in telling the OS to run a certain process on a
- limited set of CPUs only.
+ CPU affinity consists in telling the OS to run a process on a limited set
+ of CPUs only.
On Linux this is done via the ``taskset`` command.
- The number of eligible CPUs can be obtained with
- ``list(range(psutil.cpu_count()))``.
- ``ValueError`` will be raised on set in case an invalid CPU number is
- specified.
+ If no argument is passed it returns the current CPU affinity as a list
+ of integers.
+ If passed it must be a list of integers specifying the new CPUs affinity.
+ If an empty list is passed all eligible CPUs are assumed (and set);
+ on Linux this may not necessarily mean all available CPUs as in
+ ``list(range(psutil.cpu_count()))``).
>>> import psutil
>>> psutil.cpu_count()
4
>>> p = psutil.Process()
- >>> p.cpu_affinity() # get
+ >>> # get
+ >>> p.cpu_affinity()
[0, 1, 2, 3]
- >>> p.cpu_affinity([0]) # set; from now on, process will run on CPU #0 only
+ >>> # set; from now on, process will run on CPU #0 and #1 only
+ >>> p.cpu_affinity([0, 1])
>>> p.cpu_affinity()
- [0]
- >>>
- >>> # reset affinity against all CPUs
- >>> all_cpus = list(range(psutil.cpu_count()))
- >>> p.cpu_affinity(all_cpus)
- >>>
+ [0, 1]
+ >>> # reset affinity against all eligible CPUs
+ >>> p.cpu_affinity([])
Availability: Linux, Windows, FreeBSD
.. versionchanged:: 2.2.0 added support for FreeBSD
+ .. versionchanged:: 5.1.0 an empty list can be passed to set affinity
+ against all eligible CPUs.
.. method:: cpu_num()
@@ -1869,7 +1872,7 @@ Constants
.. data:: SUNOS
``bool`` constants which define what platform you're on. E.g. if on Windows,
- *WINDOWS* constant will be ``True``, all others will be ``False``.
+ :const:`WINDOWS` constant will be ``True``, all others will be ``False``.
.. versionadded:: 4.0.0
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 0417ed7f..e13866a3 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -230,6 +230,7 @@ class Error(Exception):
"""
def __init__(self, msg=""):
+ Exception.__init__(self, msg)
self.msg = msg
def __repr__(self):
@@ -828,6 +829,8 @@ class Process(object):
"""Get or set process CPU affinity.
If specified 'cpus' must be a list of CPUs for which you
want to set the affinity (e.g. [0, 1]).
+ If an empty list is passed, all egible CPUs are assumed
+ (and set).
(Windows, Linux and BSD only).
"""
# Automatically remove duplicates both on get and
@@ -836,6 +839,11 @@ class Process(object):
if cpus is None:
return list(set(self._proc.cpu_affinity_get()))
else:
+ if not cpus:
+ if hasattr(self._proc, "_get_eligible_cpus"):
+ cpus = self._proc._get_eligible_cpus()
+ else:
+ cpus = tuple(range(len(cpu_times(percpu=True))))
self._proc.cpu_affinity_set(list(set(cpus)))
# Linux, FreeBSD, SunOS
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 833cad01..16de79e5 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1564,18 +1564,33 @@ class Process(object):
def cpu_affinity_get(self):
return cext.proc_cpu_affinity_get(self.pid)
+ def _get_eligible_cpus(
+ self, _re=re.compile(b"Cpus_allowed_list:\t(\d+)-(\d+)")):
+ # See: https://github.com/giampaolo/psutil/issues/956
+ data = self._read_status_file()
+ match = _re.findall(data)
+ if match:
+ return list(range(int(match[0][0]), int(match[0][1]) + 1))
+ else:
+ return list(range(len(per_cpu_times())))
+
@wrap_exceptions
def cpu_affinity_set(self, cpus):
try:
cext.proc_cpu_affinity_set(self.pid, cpus)
except (OSError, ValueError) as err:
if isinstance(err, ValueError) or err.errno == errno.EINVAL:
- allcpus = tuple(range(len(per_cpu_times())))
+ eligible_cpus = self._get_eligible_cpus()
+ all_cpus = tuple(range(len(per_cpu_times())))
for cpu in cpus:
- if cpu not in allcpus:
+ if cpu not in all_cpus:
raise ValueError(
"invalid CPU number %r; choose between %s" % (
- cpu, allcpus))
+ cpu, eligible_cpus))
+ if cpu not in eligible_cpus:
+ raise ValueError(
+ "CPU number %r is not eligible; choose "
+ "between %s" % (cpu, eligible_cpus))
raise
# only starting from kernel 2.6.13
diff --git a/psutil/_psposix.py b/psutil/_psposix.py
index acbc7855..6debdb32 100644
--- a/psutil/_psposix.py
+++ b/psutil/_psposix.py
@@ -110,7 +110,7 @@ def wait_pid(pid, timeout=None):
# process exited due to a signal; return the integer of
# that signal
if os.WIFSIGNALED(status):
- return os.WTERMSIG(status)
+ return -os.WTERMSIG(status)
# process exited using exit(2) system call; return the
# integer exit(2) system call has been called with
elif os.WIFEXITED(status):
diff --git a/psutil/arch/windows/services.c b/psutil/arch/windows/services.c
index 8e7fff33..26e58225 100644
--- a/psutil/arch/windows/services.c
+++ b/psutil/arch/windows/services.c
@@ -308,6 +308,12 @@ psutil_winservice_query_status(PyObject *self, PyObject *args) {
// right size.
QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, NULL, 0,
&bytesNeeded);
+ if (GetLastError() == ERROR_MUI_FILE_NOT_FOUND) {
+ // Also services.msc fails in the same manner, so we return an
+ // empty string.
+ CloseServiceHandle(hService);
+ return Py_BuildValue("s", "");
+ }
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
PyErr_SetFromWindowsErr(0);
goto error;
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 37352ecf..0f0b09c3 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -1277,6 +1277,11 @@ class TestProcessAgainstStatus(unittest.TestCase):
self.assertEqual(
self.proc.cpu_affinity(), list(range(min_, max_ + 1)))
+ def test_cpu_affinity_eligible_cpus(self):
+ with mock.patch("psutil._pslinux.per_cpu_times") as m:
+ self.proc._proc._get_eligible_cpus()
+ assert not m.called
+
if __name__ == '__main__':
run_test_module_by_name(__file__)
diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py
index 6e7a5891..69d6c840 100755
--- a/psutil/tests/test_osx.py
+++ b/psutil/tests/test_osx.py
@@ -151,7 +151,7 @@ class TestSystemAPIs(unittest.TestCase):
self.assertEqual(num, psutil.cpu_count(logical=False))
def test_cpu_freq(self):
- freq = psutil.cpu_freq()[0]
+ freq = psutil.cpu_freq()
self.assertEqual(
freq.current * 1000 * 1000, sysctl("sysctl hw.cpufrequency"))
self.assertEqual(
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index fdb9f03d..74ae9330 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -104,7 +104,7 @@ class TestProcess(unittest.TestCase):
sig = p.wait()
self.assertFalse(psutil.pid_exists(test_pid))
if POSIX:
- self.assertEqual(sig, signal.SIGKILL)
+ self.assertEqual(sig, -signal.SIGKILL)
def test_terminate(self):
sproc = get_test_subprocess()
@@ -114,7 +114,7 @@ class TestProcess(unittest.TestCase):
sig = p.wait()
self.assertFalse(psutil.pid_exists(test_pid))
if POSIX:
- self.assertEqual(sig, signal.SIGTERM)
+ self.assertEqual(sig, -signal.SIGTERM)
def test_send_signal(self):
sig = signal.SIGKILL if POSIX else signal.SIGTERM
@@ -124,7 +124,7 @@ class TestProcess(unittest.TestCase):
exit_sig = p.wait()
self.assertFalse(psutil.pid_exists(p.pid))
if POSIX:
- self.assertEqual(exit_sig, sig)
+ self.assertEqual(exit_sig, -sig)
#
sproc = get_test_subprocess()
p = psutil.Process(sproc.pid)
@@ -155,7 +155,7 @@ class TestProcess(unittest.TestCase):
p.kill()
code = p.wait()
if POSIX:
- self.assertEqual(code, signal.SIGKILL)
+ self.assertEqual(code, -signal.SIGKILL)
else:
self.assertEqual(code, 0)
self.assertFalse(p.is_running())
@@ -165,7 +165,7 @@ class TestProcess(unittest.TestCase):
p.terminate()
code = p.wait()
if POSIX:
- self.assertEqual(code, signal.SIGTERM)
+ self.assertEqual(code, -signal.SIGTERM)
else:
self.assertEqual(code, 0)
self.assertFalse(p.is_running())
@@ -231,7 +231,7 @@ class TestProcess(unittest.TestCase):
else:
break
if POSIX:
- self.assertEqual(code, signal.SIGKILL)
+ self.assertEqual(code, -signal.SIGKILL)
else:
self.assertEqual(code, 0)
self.assertFalse(p.is_running())
@@ -849,10 +849,13 @@ class TestProcess(unittest.TestCase):
def test_cpu_affinity(self):
p = psutil.Process()
initial = p.cpu_affinity()
+ assert initial, initial
self.addCleanup(p.cpu_affinity, initial)
+
if hasattr(os, "sched_getaffinity"):
self.assertEqual(initial, list(os.sched_getaffinity(p.pid)))
self.assertEqual(len(initial), len(set(initial)))
+
all_cpus = list(range(len(psutil.cpu_percent(percpu=True))))
# setting on travis doesn't seem to work (always return all
# CPUs on get):
@@ -867,9 +870,14 @@ class TestProcess(unittest.TestCase):
if hasattr(p, "num_cpu"):
self.assertEqual(p.cpu_affinity()[0], p.num_cpu())
- #
- p.cpu_affinity(all_cpus)
- self.assertEqual(p.cpu_affinity(), all_cpus)
+ # [] is an alias for "all eligible CPUs"; on Linux this may
+ # not be equal to all available CPUs, see:
+ # https://github.com/giampaolo/psutil/issues/956
+ p.cpu_affinity([])
+ if LINUX:
+ self.assertEqual(p.cpu_affinity(), p._proc._get_eligible_cpus())
+ else:
+ self.assertEqual(p.cpu_affinity(), all_cpus)
if hasattr(os, "sched_getaffinity"):
self.assertEqual(p.cpu_affinity(),
list(os.sched_getaffinity(p.pid)))
@@ -1141,6 +1149,7 @@ class TestProcess(unittest.TestCase):
self.fail("num ctx switches still the same after 50.000 iterations")
def test_parent_ppid(self):
+ reap_children(recursive=True)
this_parent = os.getpid()
sproc = get_test_subprocess()
p = psutil.Process(sproc.pid)
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index 31d4c3fb..79ae6bba 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -112,7 +112,7 @@ class TestSystemAPIs(unittest.TestCase):
gone, alive = test(procs, callback)
self.assertIn(sproc3.pid, [x.pid for x in gone])
if POSIX:
- self.assertEqual(gone.pop().returncode, signal.SIGTERM)
+ self.assertEqual(gone.pop().returncode, -signal.SIGTERM)
else:
self.assertEqual(gone.pop().returncode, 1)
self.assertEqual(l, [sproc3.pid])
@@ -710,9 +710,10 @@ class TestSystemAPIs(unittest.TestCase):
self.assertGreaterEqual(value, 0)
ls = psutil.cpu_freq(percpu=True)
- if not TRAVIS:
- assert ls, ls
+ if TRAVIS and not ls:
+ return
+ assert ls, ls
check_ls([psutil.cpu_freq(percpu=False)])
if LINUX:
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index 8ce51ed0..7215560d 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -36,6 +36,7 @@ DEPS = [
"perf",
"pip",
"pypiwin32",
+ "pyreadline",
"setuptools",
"unittest2",
"wheel",