1.1 --- a/pprocess.py Thu Jun 19 21:45:03 2008 +0200
1.2 +++ b/pprocess.py Sun May 04 00:38:20 2008 +0000
1.3 @@ -4,7 +4,7 @@
1.4 A simple parallel processing API for Python, inspired somewhat by the thread
1.5 module, slightly less by pypar, and slightly less still by pypvm.
1.6
1.7 -Copyright (C) 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2005, 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU Lesser General Public License as published by the Free
1.12 @@ -20,7 +20,7 @@
1.13 with this program. If not, see <http://www.gnu.org/licenses/>.
1.14 """
1.15
1.16 -__version__ = "0.3.1"
1.17 +__version__ = "0.3.2"
1.18
1.19 import os
1.20 import sys
1.21 @@ -32,6 +32,11 @@
1.22 except ImportError:
1.23 import pickle
1.24
1.25 +try:
1.26 + set
1.27 +except NameError:
1.28 + from sets import Set as set
1.29 +
1.30 # Communications.
1.31
1.32 class AcknowledgementError(Exception):
1.33 @@ -523,6 +528,43 @@
1.34
1.35 # Utility functions.
1.36
1.37 +_cpuinfo_fields = "physical id", "core id"
1.38 +
1.39 +def get_number_of_cores():
1.40 +
1.41 + """
1.42 + Return the number of distinct, genuine processor cores. If the platform is
1.43 + not supported by this function, None is returned.
1.44 + """
1.45 +
1.46 + try:
1.47 + f = open("/proc/cpuinfo")
1.48 + try:
1.49 + processors = set()
1.50 + processor = [None, None]
1.51 +
1.52 + for line in f.xreadlines():
1.53 + for i, field in enumerate(_cpuinfo_fields):
1.54 + if line.startswith(field):
1.55 + t = line.split(":")
1.56 + processor[i] = int(t[1].strip())
1.57 + break
1.58 + else:
1.59 + if line.startswith("processor") and processor[0] is not None:
1.60 + processors.add(tuple(processor))
1.61 + processor = [None, None]
1.62 +
1.63 + if processor[0] is not None:
1.64 + processors.add(tuple(processor))
1.65 +
1.66 + return len(processors)
1.67 +
1.68 + finally:
1.69 + f.close()
1.70 +
1.71 + except OSError:
1.72 + return None
1.73 +
1.74 def create():
1.75
1.76 """