diff options
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 |