~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2009-06-05 07:10:13 UTC
  • mto: (4412.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4413.
  • Revision ID: v.ladeuil+lp@free.fr-20090605071013-2pfodtb8ye5chlt0
Fixed as per John's review.

* bzrlib/osutils.py:
(local_concurrency): Cache the calculated value by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1847
1847
                                stdout=subprocess.PIPE).communicate()[0]
1848
1848
elif sys.platform == "win32":
1849
1849
    def _local_concurrency():
1850
 
        # FIXME: If NUMBER_OF_CORES is available somewhow, it will be more
1851
 
        # precise
 
1850
        # This appears to return the number of cores.
1852
1851
        return os.environ.get('NUMBER_OF_PROCESSORS')
1853
1852
else:
1854
1853
    def _local_concurrency():
1856
1855
        return None
1857
1856
 
1858
1857
 
1859
 
def local_concurrency():
 
1858
_cached_local_concurrency = None
 
1859
 
 
1860
def local_concurrency(use_cache=True):
1860
1861
    """Return how many processes can be run concurrently.
1861
1862
 
1862
1863
    Rely on platform specific implementations and default to 1 (one) if
1863
1864
    anything goes wrong.
1864
1865
    """
 
1866
    global _cached_local_concurrency
 
1867
    if _cached_local_concurrency is not None and use_cache:
 
1868
        return _cached_local_concurrency
 
1869
 
1865
1870
    try:
1866
1871
        concurrency = _local_concurrency()
1867
1872
    except (OSError, IOError):
1870
1875
        concurrency = int(concurrency)
1871
1876
    except (TypeError, ValueError):
1872
1877
        concurrency = 1
 
1878
    if use_cache:
 
1879
        _cached_concurrency = concurrency
1873
1880
    return concurrency