diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-06 18:13:21 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-06 18:13:21 +0200 |
commit | b3cde0ee162b8f0cb67da981311c8f9c16050a62 (patch) | |
tree | 537615b8d7cfd059b2d7938a1929d9e3199fb374 /lib/git/async/util.py | |
parent | ec28ad575ce1d7bb6a616ffc404f32bbb1af67b2 (diff) | |
download | gitpython-b3cde0ee162b8f0cb67da981311c8f9c16050a62.tar.gz |
First step of testing the pool - tasks have been separated into a new module including own tests, their design improved to prepare them for some specifics that would be needed for multiprocessing support
Diffstat (limited to 'lib/git/async/util.py')
-rw-r--r-- | lib/git/async/util.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/git/async/util.py b/lib/git/async/util.py new file mode 100644 index 00000000..dabd8a42 --- /dev/null +++ b/lib/git/async/util.py @@ -0,0 +1,24 @@ +"""Module with utilities related to async operations""" + +import sys +import os + +def cpu_count(): + """:return:number of CPUs in the system + :note: inspired by multiprocessing""" + num = 0 + try: + if sys.platform == 'win32': + num = int(os.environ['NUMBER_OF_PROCESSORS']) + elif 'bsd' in sys.platform or sys.platform == 'darwin': + num = int(os.popen('sysctl -n hw.ncpu').read()) + else: + num = os.sysconf('SC_NPROCESSORS_ONLN') + except (ValueError, KeyError, OSError, AttributeError): + pass + # END exception handling + + if num == 0: + raise NotImplementedError('cannot determine number of cpus') + + return num |