~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-24 16:09:47 UTC
  • mto: (5582.10.69 weave-fmt-plugin)
  • mto: This revision was merged to the branch mainline in revision 5688.
  • Revision ID: jelmer@samba.org-20110224160947-e7kqclxnjif28v5q
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2243
2243
            termios.tcsetattr(fd, termios.TCSADRAIN, settings)
2244
2244
        return ch
2245
2245
 
2246
 
 
2247
2246
if sys.platform == 'linux2':
2248
2247
    def _local_concurrency():
2249
 
        concurrency = None
2250
 
        prefix = 'processor'
2251
 
        for line in file('/proc/cpuinfo', 'rb'):
2252
 
            if line.startswith(prefix):
2253
 
                concurrency = int(line[line.find(':')+1:]) + 1
2254
 
        return concurrency
 
2248
        try:
 
2249
            return os.sysconf('SC_NPROCESSORS_ONLN')
 
2250
        except (ValueError, OSError, AttributeError):
 
2251
            return None
2255
2252
elif sys.platform == 'darwin':
2256
2253
    def _local_concurrency():
2257
2254
        return subprocess.Popen(['sysctl', '-n', 'hw.availcpu'],
2258
2255
                                stdout=subprocess.PIPE).communicate()[0]
2259
 
elif sys.platform[0:7] == 'freebsd':
 
2256
elif "bsd" in sys.platform:
2260
2257
    def _local_concurrency():
2261
2258
        return subprocess.Popen(['sysctl', '-n', 'hw.ncpu'],
2262
2259
                                stdout=subprocess.PIPE).communicate()[0]
2290
2287
    concurrency = os.environ.get('BZR_CONCURRENCY', None)
2291
2288
    if concurrency is None:
2292
2289
        try:
2293
 
            concurrency = _local_concurrency()
2294
 
        except (OSError, IOError):
2295
 
            pass
 
2290
            import multiprocessing
 
2291
        except ImportError:
 
2292
            # multiprocessing is only available on Python >= 2.6
 
2293
            try:
 
2294
                concurrency = _local_concurrency()
 
2295
            except (OSError, IOError):
 
2296
                pass
 
2297
        else:
 
2298
            concurrency = multiprocessing.cpu_count()
2296
2299
    try:
2297
2300
        concurrency = int(concurrency)
2298
2301
    except (TypeError, ValueError):