Skip to content

Commit 0d6c0f0

Browse files
committed
Merge pull request #4296 from neurodebian/master
Use psutil to set process affinity (test_perf.py) + minor pylint-friendliness for ._ix
2 parents 2f44c19 + d30e404 commit 0d6c0f0

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ Optional dependencies
9999

100100
- `BeautifulSoup4`_ and `html5lib`_ (Any recent version of `html5lib`_ is
101101
okay.)
102-
- `BeautifulSoup4`_ and `lxml`_
103-
- `BeautifulSoup4`_ and `html5lib`_ and `lxml`_
102+
- `BeautifulSoup4`_ and `lxml`_
103+
- `BeautifulSoup4`_ and `html5lib`_ and `lxml`_
104104
- Only `lxml`_, although see :ref:`HTML reading gotchas <html-gotchas>`
105105
for reasons as to why you should probably **not** take this approach.
106106

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def axes(self):
567567

568568
@property
569569
def ix(self):
570-
if self._ix is None:
570+
if self._ix is None: # defined in indexing.py; pylint: disable=E0203
571571
self._ix = _SeriesIndexer(self, 'ix')
572572

573573
return self._ix

vb_suite/test_perf.py

+33-11
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,15 @@
9898
dest='hrepeats',
9999
default=1,
100100
type=int,
101-
help='Implies -H, number of times to run the vbench suite on the head commit.\n'
102-
'Each iteration will yield another column in the output.'
103-
)
101+
help='implies -H, number of times to run the vbench suite on the head commit.\n'
102+
'Each iteration will yield another column in the output' )
104103
parser.add_argument('-a', '--affinity',
105104
metavar="a",
106105
dest='affinity',
107106
default=1,
108107
type=int,
109-
help='Set processor affinity of the process. THe default is to bind to cpu/core #1 only.'
110-
'requires the "affinity" python module.' )
111-
108+
help='set processor affinity of process by default bind to cpu/core #1 only. '
109+
'Requires the "affinity" or "psutil" python module, will raise Warning otherwise')
112110
parser.add_argument('-u', '--burnin',
113111
metavar="u",
114112
dest='burnin',
@@ -388,14 +386,38 @@ def main():
388386
random.seed(args.seed)
389387
np.random.seed(args.seed)
390388

389+
affinity_set = False
390+
391+
# try psutil first since it is more commonly present and better
392+
# maintained. Some people experienced problems with affinity package
393+
# (see https://code.google.com/p/psutil/issues/detail?id=238 for more references)
391394
try:
392-
import affinity
393-
affinity.set_process_affinity_mask(0,args.affinity)
394-
assert affinity.get_process_affinity_mask(0) == args.affinity
395-
print("CPU affinity set to %d" % args.affinity)
395+
import psutil
396+
if hasattr(psutil.Process, 'set_cpu_affinity'):
397+
psutil.Process(os.getpid()).set_cpu_affinity([args.affinity])
398+
affinity_set = True
396399
except ImportError:
397-
print("Warning: The 'affinity' module is not available.")
400+
pass
401+
402+
if not affinity_set:
403+
try:
404+
import affinity
405+
affinity.set_process_affinity_mask(0, args.affinity)
406+
assert affinity.get_process_affinity_mask(0) == args.affinity
407+
affinity_set = True
408+
except ImportError:
409+
pass
410+
411+
if not affinity_set:
412+
import warnings
413+
warnings.warn("\n\n"
414+
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
415+
"The 'affinity' or 'psutil' >= 0.5.0 modules are not available, results may be unreliable\n"
416+
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"
417+
)
398418
time.sleep(2)
419+
else:
420+
print("CPU affinity set to %d" % args.affinity)
399421

400422
print("\n")
401423
prprint("LOG_FILE = %s" % args.log_file)

0 commit comments

Comments
 (0)