James Antill
2011-11-30 15:42:32 UTC
---
createrepo/__init__.py | 3 +++
createrepo/utils.py | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/createrepo/__init__.py b/createrepo/__init__.py
index 014765a..2d3514e 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -48,6 +48,7 @@ except ImportError:
from utils import _gzipOpen, compressFile, compressOpen, checkAndMakeDir, GzipFile, \
checksum_and_rename, split_list_into_equal_chunks
+from utils import num_cpus_online
import deltarpms
__version__ = '0.9.9'
@@ -606,6 +607,8 @@ class MetaDataGenerator:
# open the files they created and write them out to our metadata
# add up the total pkg counts and return that value
self._worker_tmp_path = tempfile.mkdtemp() # setting this in the base object so we can clean it up later
+ if self.conf.workers < 1:
+ self.conf.workers = num_cpus_online()
worker_chunks = split_list_into_equal_chunks(pkgfiles, self.conf.workers)
worker_cmd_dict = {}
worker_jobs = {}
diff --git a/createrepo/utils.py b/createrepo/utils.py
index c5cec64..16c57db 100644
--- a/createrepo/utils.py
+++ b/createrepo/utils.py
@@ -200,6 +200,22 @@ def split_list_into_equal_chunks(seq, num_chunks):
return out
+def num_cpus_online(unknown=1):
+ if not hasattr(os, "sysconf"):
+ return unknown
+
+ if not os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
+ return unknown
+
+ ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
+ try:
+ if int(ncpus) > 0:
+ return ncpus
+ except:
+ pass
+
+ return unknown
+
class MDError(Exception):
def __init__(self, value=None):
createrepo/__init__.py | 3 +++
createrepo/utils.py | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/createrepo/__init__.py b/createrepo/__init__.py
index 014765a..2d3514e 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -48,6 +48,7 @@ except ImportError:
from utils import _gzipOpen, compressFile, compressOpen, checkAndMakeDir, GzipFile, \
checksum_and_rename, split_list_into_equal_chunks
+from utils import num_cpus_online
import deltarpms
__version__ = '0.9.9'
@@ -606,6 +607,8 @@ class MetaDataGenerator:
# open the files they created and write them out to our metadata
# add up the total pkg counts and return that value
self._worker_tmp_path = tempfile.mkdtemp() # setting this in the base object so we can clean it up later
+ if self.conf.workers < 1:
+ self.conf.workers = num_cpus_online()
worker_chunks = split_list_into_equal_chunks(pkgfiles, self.conf.workers)
worker_cmd_dict = {}
worker_jobs = {}
diff --git a/createrepo/utils.py b/createrepo/utils.py
index c5cec64..16c57db 100644
--- a/createrepo/utils.py
+++ b/createrepo/utils.py
@@ -200,6 +200,22 @@ def split_list_into_equal_chunks(seq, num_chunks):
return out
+def num_cpus_online(unknown=1):
+ if not hasattr(os, "sysconf"):
+ return unknown
+
+ if not os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
+ return unknown
+
+ ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
+ try:
+ if int(ncpus) > 0:
+ return ncpus
+ except:
+ pass
+
+ return unknown
+
class MDError(Exception):
def __init__(self, value=None):
--
1.7.6.4
1.7.6.4