From 98c65ac6ac0fdb744b3de57cdcee7a1d01b67069 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 1 Jul 2013 14:17:10 -0400 Subject: [PATCH 1/2] ENH: test_perf.py - use psutil to set affinity (if absent functionality - then affinity module) original affinity module is not commonly installed, has known issues, and was not updated since 2006. psutil is already used in parts of pandas, so it would be logical to use it instead by default. --- vb_suite/test_perf.py | 44 ++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/vb_suite/test_perf.py b/vb_suite/test_perf.py index a24eefa21aca3..f171f48410ce0 100755 --- a/vb_suite/test_perf.py +++ b/vb_suite/test_perf.py @@ -98,17 +98,15 @@ dest='hrepeats', default=1, type=int, - help='Implies -H, number of times to run the vbench suite on the head commit.\n' - 'Each iteration will yield another column in the output.' - ) + help='implies -H, number of times to run the vbench suite on the head commit.\n' + 'Each iteration will yield another column in the output' ) parser.add_argument('-a', '--affinity', metavar="a", dest='affinity', default=1, type=int, - help='Set processor affinity of the process. THe default is to bind to cpu/core #1 only.' - 'requires the "affinity" python module.' ) - + help='set processor affinity of process by default bind to cpu/core #1 only. ' + 'Requires the "affinity" or "psutil" python module, will raise Warning otherwise') parser.add_argument('-u', '--burnin', metavar="u", dest='burnin', @@ -388,14 +386,38 @@ def main(): random.seed(args.seed) np.random.seed(args.seed) + affinity_set = False + + # try psutil first since it is more commonly present and better + # maintained. Some people experienced problems with affinity package + # (see https://code.google.com/p/psutil/issues/detail?id=238 for more references) try: - import affinity - affinity.set_process_affinity_mask(0,args.affinity) - assert affinity.get_process_affinity_mask(0) == args.affinity - print("CPU affinity set to %d" % args.affinity) + import psutil + if hasattr(psutil.Process, 'set_cpu_affinity'): + psutil.Process(os.getpid()).set_cpu_affinity([args.affinity]) + affinity_set = True except ImportError: - print("Warning: The 'affinity' module is not available.") + pass + + if not affinity_set: + try: + import affinity + affinity.set_process_affinity_mask(0, args.affinity) + assert affinity.get_process_affinity_mask(0) == args.affinity + affinity_set = True + except ImportError: + pass + + if not affinity_set: + import warnings + warnings.warn("\n\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "The 'affinity' or 'psutil' >= 0.5.0 modules are not available, results may be unreliable\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n" + ) time.sleep(2) + else: + print("CPU affinity set to %d" % args.affinity) print("\n") prprint("LOG_FILE = %s" % args.log_file) From d30e4049a587bca8aab939c88ba74a0333484718 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 19 Jul 2013 15:56:37 -0400 Subject: [PATCH 2/2] minor: some trailing spaces and a pylint "pragma" to stop complaining about Series._ix defined elsewhere --- README.rst | 4 ++-- pandas/core/series.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 85868176722bd..da789e704ebad 100644 --- a/README.rst +++ b/README.rst @@ -99,8 +99,8 @@ Optional dependencies - `BeautifulSoup4`_ and `html5lib`_ (Any recent version of `html5lib`_ is okay.) - - `BeautifulSoup4`_ and `lxml`_ - - `BeautifulSoup4`_ and `html5lib`_ and `lxml`_ + - `BeautifulSoup4`_ and `lxml`_ + - `BeautifulSoup4`_ and `html5lib`_ and `lxml`_ - Only `lxml`_, although see :ref:`HTML reading gotchas ` for reasons as to why you should probably **not** take this approach. diff --git a/pandas/core/series.py b/pandas/core/series.py index 15a425fb3fd73..b77dfbfd9618c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -567,7 +567,7 @@ def axes(self): @property def ix(self): - if self._ix is None: + if self._ix is None: # defined in indexing.py; pylint: disable=E0203 self._ix = _SeriesIndexer(self, 'ix') return self._ix